|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
insert into multiple tables
*****PLEASE HELP*****
Need SQL code to insert data into multiple tables. I have a one to many relationship. The reason for multible tables is so I can have only one instance of an idividual but may have multiple instances of addresses or other data in other tables. There will be more than two tables. However if I see the code I should be able to add more tables. I will be using a web form to send data to MSSQL or MS ACCESS DATABASE. Example: Table 1 "NAMES" SUBJECT_ID (PRIMARY KEY--AUTO NUMBER) LASTNAME FIRSTNAME INIT DOB SS Table 2 "ADDRESS" SUBJECT_ID (NOT PRIMARY KEY--RELATIONSHIP TO NAMES) STREET CITY STATE ZIP |
|
#2
|
|||
|
|||
|
RE: insert into multiple tables
The only way to insert into multiple tables is a) use two inserts to insert the same data into the seperate tables or b) use triggers on the first table to update/insert data to the second table when any of the relevant fields in the first table are inserted/updated.
Also, the trigger method will only work on MSSQL, as I don't think MS Access has any kind of trigger capabilities. (Not entirely certain about that, as I've never tried to do any kind of intensive databasing with Access) |
|
#3
|
|||
|
|||
|
RE: insert into multiple tables
I tried using two insert into commands. It give me error messages. Can you give me example code using two insert into's?
Thanks |
|
#4
|
|||
|
|||
|
RE: insert into multiple tables
Sure, given that you know how to correctly retrieve whatever data you need out of the forms, use code similar to the following:
$query1 = "insert into names (lastname, firstname, init, dob, ss) values ('$lastname','$firstname','$init','$dob', '$ss')"; $query2 = "insert into address (subject_id, street, city, state, zip) values ('$lastname $firstname', '$street', '$city', '$state', '$zip')"; $result1 = mssql_query($query1); $result2 = mssql_query($query2); |
|
#5
|
|||
|
|||
|
RE: insert into multiple tables
jpreed00 Thanks.
I do not have it yet, but i wanted to say thanks. Will check back tomorrow. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > insert into multiple tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|