Empty string inserting a zero, not a null

前端 未结 4 1342
一整个雨季
一整个雨季 2021-02-14 07:42

My insert statement looks like this:

INSERT INTO foo (bar) VALUES (\'\');

The bar field was created like so:

bar I         


        
4条回答
  •  再見小時候
    2021-02-14 08:18

    You're not inserting NULL into the table; you're inserting an empty string (which apparently maps to zero as an int). Remember that NULL is a distinct value in SQL; NULL != ''. By specifying any value (other than NULL), you're not inserting NULL. The default only gets used if you don't specify a value; in your example, you specified a string value to an integer column.

提交回复
热议问题