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
 More effecient way to insert data?

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2009-03-05 : 12:32:11
I'm looking for a more efficient way to insert data into multiple tables. Before I explain what I currently do, I'll give you some sample tables/data so it'll make more sense.


Employee Emp_Interests Interests
empID empID interestID
empFirst interestID interestType
empLast


Imagine there's a form to insert Employee data, including their interests. What I've been doing is inserting data into the Employee table, returning the empID that is created, and then using it to insert the interestTypes and empID in the Emp_Interests table.

There's go to be a more efficient way of doing this. Let me know if my example wasn't clear enough.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-05 : 12:51:37
thats the way to go unless you're using sql 2005 in which case you can use OUTPUT operator to get empIDs together in a table variable and then use it later to insert to emp_interests table, similarly for interestID
Go to Top of Page

crugerenator
Posting Yak Master

126 Posts

Posted - 2009-03-05 : 13:08:01
Wow, really? I thought there would be some neat trick to use. Is it possible to change the database design to make it more efficient in a situation like this?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-05 : 13:10:27
why should you change design? the design as of now looks ok. what you need is to use oiutput operator if sql 2005
Go to Top of Page
   

- Advertisement -