Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 9th, 2003, 02:08 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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

Reply With Quote
  #2  
Old July 9th, 2003, 03:00 AM
jpreed00 jpreed00 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 20 jpreed00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #3  
Old July 9th, 2003, 03:09 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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

Reply With Quote
  #4  
Old July 9th, 2003, 03:16 AM
jpreed00 jpreed00 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 20 jpreed00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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);

Reply With Quote
  #5  
Old July 9th, 2003, 03:35 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: insert into multiple tables

jpreed00 Thanks.

I do not have it yet, but i wanted to say thanks. Will check back tomorrow.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > insert into multiple tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT