0

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.

2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by G_Waddell
1

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...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.