Why isn't my default value used?


If you have a table with some column defined as NOT NULL DEFAULT 'something' you might get surprise when you try to insert NULL into such column. Example:

create table T1 ( x integer, y integer not null default 10 );

insert into T1(x, y) values (5, null);


You expect that 10 gets written to column y, but you get error message instead.

The reason is that the default values are only used when you don't insert into such column at all:

insert into T1(x) values(5);

What of all your columns have defaults and you want them all? Well, Firebird 2.1 should support such inserts once the final version is out.


Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.



All contents are copyright © 2007-2024 FirebirdFAQ.org unless otherwise stated in the text.


Links   Firebird   News   FlameRobin   Powered by FB: Home Inventory   Euchre  
Add content   About  

Categories
 Newbies
 SQL
 Installation and setup
 Backup and restore
 Performance
 Security
 Connectivity and API
 HOWTOs
 Errors and error codes
 Miscellaneous