On Wednesday 26 November 2003 17.51, Millaway, John wrote:
> Inserting a NULL into a NOT NULL column used to automatically get the
> DEFAULT value. I realize that it was non-portable, non-standard behavior,
> but the code relies on it. How do I get this behavior in the 4.0.x server?
>
> mysql> CREATE TABLE t (a INT NOT NULL DEFAULT 0);
> Query OK, 0 rows affected (0.00 sec)
>
> mysql> INSERT INTO t (a) VALUES (NULL);
> ERROR 1048: Column 'a' cannot be null

Just leave the NOT NULL column out when inserting and it will get set to its 
default.

CREATE TABLE t2 (a INT NOT NULL DEFAULT 0, b INT);
INSERT INTO t2 (b) VALUES(666);
INSERT INTO t2 SET b=5;
In both cases column a will get DEFAULT value.

If you only have exactly one column in your table (makes any sense?) this will 
work:
INSERT INTO t VALUES();

Hope it helps
Mike

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to