CREATE TABLE tImprumuturi
(
ID_Imprumut INT IDENTITY PRIMARY KEY,
DataImprumut DATE DEFAULT getdate(),
DataScadenta AS ( dateadd(day, 2, DataImprumut) ) persisted,
CodCD CHAR(10) FOREIGN KEY REFERENCES tCD(CodCd)NOT NULL,
CodCV CHAR(10) FOREIGN KEY REFERENCES tCaseteVideo(CodCaseta),
CodAb CHAR(10) FOREIGN KEY REFERENCES tAbonati(CodAbonat) NOT NULL,
CONSTRAINT ucCodes UNIQUE (CodCD, CodCV, CodAb)
)
我不想拥有许多相同的 CodCD OR CodCV OR CodAb,但绝不希望有两个具有相同 CodCD AND CodCV AND CodAb 的记录。如您所见,我的代码在顶部,即使我有指令CONSTRAINT ucCodes UNIQUE (CodCD,CodCV,CodAb)
,它仍然允许我插入两个或更多具有相同CodCD
andCodCV
和的记录CodAb
。下面你可以看到我的记录
insert into tImprumuturi(CodCV,CodCD,CodAb)
values('CV21','CD20','ab9'),
('CV21','CD19','ab9')