+ 1

Does a unique constraint allows a null value to be inserted once? Or the Check constraint

26th Jun 2019, 7:31 PM
mvtin
mvtin - avatar
2 Antworten
+ 2
This may surprise you but In MySQL, yes. More than once even. You could repeatedly insert null into a unique-constrained field and MySQL would not complain. If you had a composite unique constraint, in other words a unique constraint spanning multiple fields, a null in any of the fields causes this behaviour too. There is more discussion on that here: https://stackoverflow.com/questions/3712222/does-mysql-ignore-null-values-on-unique-constraints Most of my experience is with MySQL and I didn't quickly find conclusive information on if other vendors such as Postgres and Oracle do the same.
27th Jun 2019, 2:33 AM
Josh Greig
Josh Greig - avatar
+ 1
How about the check constraint?
27th Jun 2019, 11:31 AM
mvtin
mvtin - avatar