Allow null in unique column

前端 未结 6 1558
走了就别回头了
走了就别回头了 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:40

    Drop the email column from the table. Put it in a new table where it can be NOT NULL and UNIQUE:

    CREATE TABLE CompanyEmail
     (
        CompanyUniqueID INT NOT NULL PRIMARY KEY
           REFERENCES MMCompany (CompanyUniqueID),
        Email VARCHAR(75) NOT NULL UNIQUE
     );
    

    Avoid nullable UNIQUE constraints.

提交回复
热议问题