Reputation: 45
I can't get a table to accept "" or '' and use the default value. It is inserting NULL instead.
I am trying these commands in the direct input sql window.
INSERT INTO test01 VALUES ("", now(), "");
INSERT INTO test01 VALUES ('', now(), '');
But both just give NULL in the 3rd column. The structure is set to non-null with a default value of "yes". (Without quotation marks).
Here is a screenshot of the structure. You can see NULL is not checked. http://garryjones.se/extras/so3.png
Upvotes: 1
Views: 3181
Reputation: 171
You could use the DEFAULT keyword: INSERT INTO test01 VALUES ("", now(), DEFAULT);
Upvotes: 0
Reputation: 16117
Other is already explain the reason here I am adding one more point you are also using current time stamp on update so do not need to use this column as well.
INSERT INTO test01 (t1) VALUES ('')
Upvotes: 0
Reputation: 47444
Default values only work if no value is inserted/updated. If you explicitly set it to an empty string (which is NOT the same as a NULL
value) then it will end up with an empty string in the column. Instead of the code above you should eliminate the column from the INSERT
statement at all:
INSERT INTO test01 (t1, t2) VALUES ('', now())
Upvotes: 3