I am creating two tables RegistrationHeader and RegistrationDetail. How can i add a constraint that when i delete RegistrationHeader table to automaicaly delete the RegistrationDetail table.
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)
);
Thanks for the help!