On Sun, 29 Aug 2004 22:26:25 +0100, Tim Bunce <[EMAIL PROTECTED]> wrote:
> Do any databases support CREATE TABLE statement with fields
> having a DEFAULT clause without a NOT NULL?
> 
>         CREATE TABLE foo (
>             bar INTEGER,
>             baz INTEGER DEFAULT 42
>         )

Yes.  Informix does.

> and if so, under what circumstances is the default applied?

When no value is supplied for the column in the insert statement.
INSERT INTO foo(baz) VALUES(12); -- baz gets the default!

> I can imagine it meaning that
> 
>         INSERT INTO foo (bar, baz) VALUES (1, NULL)
> 
> doesn't trigger the DEFAULT, but that

Correct: a legitimate "value" - NULL - is supplied and stored.

>         INSERT INTO foo (bar) VALUES (1)
> 
> would.

Correct.

> But I'm just guessing. I'm not aware of any that do that as I've
> never looked into it before.
> 
> Tim [trying to write a book, it seems]

Good luck with the writing...


-- 
Jonathan Leffler <[EMAIL PROTECTED]>  #include <disclaimer.h>
Guardian of DBD::Informix - v2003.04 - http://dbi.perl.org
"I don't suffer from insanity - I enjoy every minute of it."

Reply via email to