On Tue, Apr 24, 2012 at 09:03:34AM -0700, stefanos sofroniou scratched on the wall: > Dear all, > > I have been gazing my code for amount 20 minutes now and I really need your > help with this silly yet simple code. > > CREATE TABLE testing( > id integer primary key, > name text not null default 'hello'); > > * If I insert an empty row with null values, it does not work. > > * If I insert an N value to id, name adds default string as its value. > * If I insert any character in name, id automatically adds a value. > * If I run this line "insert into testing default values;" it works > just fine. > Can you clarify this just a bit please about the first line with null values? > > I know that sounds silly since I have declared my name as not null, but > should not the shell caught this and check for its default alternative > if any?
Trying to insert a NULL does not trigger a default value. Unless specified, every column has a default value of NULL. There is nothing magic about NULLs and defaults, however... just assume every other column has a "default NULL" tacked on to the end. The default "default NULL" does not mean if you provide an explicit NULL, an otherwise default value will be used. If you said you wanted a NULL, it will try to insert a NULL. Only you can't do that because of the NOT NULL. The only way to get a default value is to not define it. Passing NULL doesn't work. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable." -- Angela Johnson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users