Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inserting data into multiple related tables

Author  Topic 

norty911
Starting Member

41 Posts

Posted - 2007-06-18 : 06:39:05
Hey guys up until now i've only inserted data into a single table. Now I have a form that collects information over a span of three forms. Each form has a table related to it and these three tables are related to each other.

What I want to know is:
1)How do you go abouts inserting data into multiple related tables that have constraints on them?

2)Would you use a stored procedure in an instance like this?

3)At what stage would you execute the sql queries. I assume you do this once you have collected all the required information as opposed to: Enter info into form1, submit form1 data to database... enter info into form2, submit form2 data into database etc

Any help would be greatly appreciated!

Say for instance I have three related tables.

table1
------
tbl1_id
tbl1_data1
tbl1_data2

table2
------
tbl2_id
tbl2_data1
tbl2_data2

table3
------
tbl3_id
tbl3_data1
tbl3_data2

table1 has a one-to-many relationship with table2
table3 has a one-to-one relationship with table2

norty911
Starting Member

41 Posts

Posted - 2007-06-18 : 10:46:45
Could someone pls help me with this as it is urgent!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-06-18 : 11:33:46
Insert data into Table2 first. Record the tbl2_id.
Now insert in table Table1 and Table3.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-06-18 : 11:35:04
you first insert data into parent tables then into child tables.

db data entry is usually done at the end page. you can cache the data until then.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -