How can I insert NULL value into INT column with MySQL? Is it possible?
You can insert NULL value into an int column with a condition i.e. the column must not have NOT NULL constraints.
You just put NULL instead of value in INSERT statement. Show activity on this post. Show activity on this post. The optimal solution for this is provide it as '0' and while using string use it as 'null' when using integer.
You also can specify the NULL keyword in the VALUES clause to indicate that a column should be assigned a NULL value. The following example inserts values into three columns of the orders table: INSERT INTO orders (orders_num, order_date, customer_num) VALUES (0, NULL, 123);
Code Inspection: Insert NULL into NOT NULL column You cannot insert NULL values in col1 and col2 because they are defined as NOT NULL. If you run the script as is, you will receive an error. To fix this code, replace NULL in the VALUES part with some values (for example, 42 and 'bird' ).
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);
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With