Greetings, i just want to ask how to insert a data with fk. Like if i insert a data on tblPatient, the patientID will be displayed on the tblRecord.
is it just a normal insert into tblpatient or is there another code for it?
Thanks.
Greetings, i just want to ask how to insert a data with fk. Like if i insert a data on tblPatient, the patientID will be displayed on the tblRecord.
is it just a normal insert into tblpatient or is there another code for it?
Thanks.
Hi,
You would run your insert on your table as normal passing the foreign key in as a value. For instance, to use your patient example, I want to record a visit by a patient with an ID of 1 to the doctor with an id of 2...INSERT INTO tblVisits(VisitDate, patientID, doctorID, cost) Values('2014-01-27 14:30', 1, 2, 56.66)
Assuming there is also a tblDoctors, you have just inserted 2 foreign keys into the Visits table, patientID and doctorID, of course, you would have to have a doctor with an ID of 2 and a patient with an ID of 1...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.