Allow null in unique column

前端 未结 6 1446
走了就别回头了
走了就别回头了 2020-12-08 02:13

I\'ve created the following table:

CREATE TABLE MMCompany (
   CompanyUniqueID BIGSERIAL PRIMARY KEY NOT NULL, 
   Name VARCHAR (150) NOT NULL,
   PhoneNumb         


        
6条回答
  •  有刺的猬
    2020-12-08 02:36

    Some databases do not allow multiple null values, for example the SQL Server documentation states that "multiple null values are considered duplicates". On databases that do not allow nullable UNIQUE constraints you could try this (from GuidoG's answer to another question):

    CREATE UNIQUE NONCLUSTERED INDEX IDX_Email
    ON MMCompany (Email)
    WHERE Email IS NOT NULL;
    

提交回复
热议问题