Sunday, September 23, 2012

MySQL - Create Table with Foreign Key


Example:

Create table tblPatientPrescription(
PrescriptionId int auto_increment primary key, PatientId int, DoctorID int,
INDEX inx_tblPatientPrescription_pid(PatientId),
INDEX inx_tblPatientPrescription_did(DoctorID),
Description1 varchar(100),
Description2 varchar(100),
foreign key(PatientId) references tblpatientinfo(patientid) ON DELETE CASCADE,
foreign key(DoctorID) references tblDoctorInfo(DoctorID)ON DELETE CASCADE)

No comments:

Post a Comment