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 或 CodCV 或 CodAb,但绝不希望两条记录具有相同的 CodCD 和 CodCV 和 CodAb。如您所见,我的代码在顶部,即使我有指令CONSTRAINT ucCodes UNIQUE (CodCD,CodCV,CodAb)
,它仍然允许我插入两个或多个具有相同 CodCD AND CodCV AND CodAb 的记录。下面你可以看到我的记录
insert into tImprumuturi(CodCV,CodCD,CodAb)
values('CV21','CD20','ab9')
insert into tImprumuturi(CodCV,CodCD,CodAb)
values('CV21','CD19','ab9')