Reputation: 1195
How can I insert NULL value into INT column with MySQL? Is it possible?
Upvotes: 38
Views: 150983
Reputation: 1
The optimal solution for this is provide it as '0' and while using string use it as 'null' when using integer.
ex:
INSERT INTO table_name(column_name) VALUES(NULL);
Upvotes: -3
Reputation: 1
Just use the insert query and put the NULL keyword without quotes. That will work-
INSERT INTO `myDatabase`.`myTable` (`myColumn`) VALUES (NULL);
Upvotes: 0
Reputation: 107826
2 ways to do it
insert tbl (other, col1, intcol) values ('abc', 123, NULL)
or just omit it from the column list
insert tbl (other, col1) values ('abc', 123)
Upvotes: 16
Reputation: 41
Does the column allow null?
Seems to work. Just tested with phpMyAdmin, the column is of type int that allows nulls:
INSERT INTO `database`.`table` (`column`) VALUES (NULL);
Upvotes: 4
Reputation: 7376
If the column has the NOT NULL
constraint then it won't be possible; but otherwise this is fine:
INSERT INTO MyTable(MyIntColumn) VALUES(NULL);
Upvotes: 52
Reputation: 60115
If column is not NOT NULL
(nullable).
You just put NULL
instead of value in INSERT
statement.
Upvotes: 3