我正在創建兩個表RegistrationHeader和RegistrationDetail。我如何添加一個約束,當我刪除RegistrationHeader表automayy刪除RegistrationDetail表。SQL Server中表之間的約束,刪除一個應該刪除另一個
create table RegistrationHeader(
RegistrationNo numeric
,BillingID varchar(30) not null
,RegistrationDate date not null
,PaymentType varchar check (PaymentType = 'CC' or PaymentType = 'PO' or PaymentType = 'Check') not null
,CCNumber numeric check(CCNumber >= 15 and CCNumber <=16)
,PONumber varchar(30)
,CheckNumber varchar(10)
,primary key(RegistrationNo)
,foreign key(BillingId) references Person(UserID)
,constraint CC_CCNumber_constr check(
(PaymentType = 'CC' and CCNumber is not null)
or
(PaymentType != 'CC' and CCNumber is null)
)
,constraint PO_PONumber_constr check(
(PaymentType = 'PO' and (PONumber is not null or PONumber != ''))
or
(PaymentType != 'PO' and PONumber is null)
)
,constraint CheckNumber_type_constr check(PaymentType != 'Check' and CheckNumber is null)
);
create table RegistrationDetail(
RegistrationNo numeric
,LineNumber numeric
,CourseID numeric(10) not null
,AttendeeID varchar(30) not null
primary key(RegistrationNo,LineNumber)
);
感謝您的幫助!
SQL Server,MySQL等...? – Tom
在我提到的SQL頭文件中,我會將其大寫。謝謝 – setlio
沒錯。有多種類型的SQL DBMS。 – Tom