Unique constraint that allows empty values in MySQL

五迷三道 提交于 2019-11-26 17:30:38

Yes, you can do this. See the MySQL reference (version 5.5).

A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL.

Yes, if you make the product code column nullable (not declared with NOT NULL), the unique key will allow multiple rows with NULL product codes.

MySQL still allows for multiple rows to have a value of NULL in a unique column.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!