Insert NULL value into INT column

前端 未结 6 1444
名媛妹妹
名媛妹妹 2020-12-30 20:05

How can I insert NULL value into INT column with MySQL? Is it possible?

相关标签:
6条回答
  • 2020-12-30 20:09

    If column is not NOT NULL (nullable).

    You just put NULL instead of value in INSERT statement.

    0 讨论(0)
  • 2020-12-30 20:13

    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);
    
    0 讨论(0)
  • 2020-12-30 20:17

    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);
    
    0 讨论(0)
  • 2020-12-30 20:26

    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)

    0 讨论(0)
  • 2020-12-30 20:30

    Just use the insert query and put the NULL keyword without quotes. That will work-

    INSERT INTO `myDatabase`.`myTable` (`myColumn`) VALUES (NULL);
    
    0 讨论(0)
  • 2020-12-30 20:33

    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);
    
    0 讨论(0)
提交回复
热议问题