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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 inserting process to the seperated tables

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2007-08-14 : 23:13:58
i have a source table : enrollment
enrollment_key
Unique_id
gender
DOB
episod1
episod2
episod3
race

I need to create a process that will insert records in enrollment table to registration and episod table( these two table has foreigen key relationship)

registration table
enrollment_key in enrollment table will be the primary key of registration table:registration_key
registration_key (pk)
unique_id
gender
DOB

and episod table
episod_key
registration_key (FK)
episod1
episod2
episod3
race

what is the best process to insert the records from enrollment table to registration and epiosd table?



rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-14 : 23:20:53
Tried this?

insert into tab_name1 (col list) select col list from tab_name2 where ...
Go to Top of Page

jung1975
Aged Yak Warrior

503 Posts

Posted - 2007-08-14 : 23:45:14
i am not quite sue your solution will work this case,,
how can i make the entry to two tables at the sme time..which has a foreign key relationship.
dffernet columns in each row need to go to two different tables



Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-14 : 23:46:07
You have to do 2 separate INSERTS. Insert into the child table first followed by the parent table.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -