Why does MySQL allow to update a NOT NULL column to NULL?

前端 未结 2 399
暗喜
暗喜 2021-01-12 20:07

I\'m running MySql in ubuntu 10.10. I created a table called \'employee\' having 3 field names empno, name and salary

相关标签:
2条回答
  • 2021-01-12 20:45

    I don't see the problem, you set the column to NOT NULL, (which doesn't allow NULL values) and now it won't let you set it to NULL, which would be the expected behaviour.

    The reason you have 0s in your DB is because 0 would be the result of casting NULL to an int.

    0 讨论(0)
  • 2021-01-12 20:47

    You must not have SQL_MODE set to strict on you ubuntu installation.

    Issue

    SET SQL_MODE='STRICT_ALL_TABLES'
    

    or add

    SQL_MODE='STRICT_ALL_TABLES'
    

    under [mysqld] to your my.cnf on Ubuntu.

    0 讨论(0)
提交回复
热议问题