insert into 2 sql tables

  • Thread starter Thread starter GotDotNet?
  • Start date Start date
G

GotDotNet?

Is there a way to insert data into 2 tables but use the ID from table 1 and
insert that into table 2 as well as several other values?

so I can insert a ID into table1, I then need that ID and insert that with
the records into table2.
I'm not using a a stored procedure, I'm using inline sql statements.

should I do the insert first then do a select on table1 and use that
parameter or is there another way to do this?
 
You say you aren't using stored procs, are you able to put a trigger
on table1 to do the table 2 stuff?
 
Is there a way to insert data into 2 tables but use the ID from table 1 and
insert that into table 2 as well as several other values?

so I can insert a ID into table1, I then need that ID and insert that with
the records into table2.
I'm not using a a stored procedure, I'm using inline sql statements.

should I do the insert first then do a select on table1 and use that
parameter or is there another way to do this?

SELECT scope_identity()

after your INSERT statement into the first table.
 
that won't work becaue the identity column is not the id field I need. I'm
generating a GUID that I need to all the tables for an ID field.
 
Write out the basic DDL please.

Are you using Guid's for the primary key? Or using IDENTITY's?


Dept
_____
DeptUUID , DeptName


Emp
_____
EmpUUID , EmpName , EmpDeptUUID


Are you creating a Dept, and then trying to create an Emp, but you need the
DeptUUID for the (fk) EmpDeptUUID ?

Something like that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top