Unique key with NULLs

前端 未结 10 817
一整个雨季
一整个雨季 2020-12-03 00:48

This question requires some hypothetical background. Let\'s consider an employee table that has columns name, date_of_birth, tit

10条回答
  •  借酒劲吻你
    2020-12-03 01:05

    There is a another way to do it. Adding a column(non-nullable) to represent the String value of date_of_birth column. The new column value would be ""(empty string) if date_of_birth is null.

    We name the column as date_of_birth_str and create a unique constraint employee(name, date_of_birth_str). So when two recoreds come with the same name and null date_of_birth value, the unique constraint still works.

    But the efforts of maintenance for the two same-meaning columns, and, the performance harm of new column, should be considered carefully.

提交回复
热议问题