x

Insert into identity column table use that identity column value to insert in second table

I have 2 tables. I need to insert row to a table so that i will get the identity column value using that identity column value i need to add a row in the second table.How to do it without using triggers? Table 1: userid identitycolumn primary key val1 varchar null val2 varchar null

Table2
userid not null
value3 null
value4 null

more ▼

asked Jul 04 '10 at 06:50 PM in Default

winza gravatar image

winza
2 1 2 2

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first


INSERT Table1 (val1,val2)
OUTPUT Inserted.UserID,NULL,NULL INTO Table2
VALUES('1','2')
more ▼

answered Jul 04 '10 at 08:20 PM

Scot Hauder gravatar image

Scot Hauder
5.9k 13 15 18

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x103

asked: Jul 04 '10 at 06:50 PM

Seen: 747 times

Last Updated: Jul 04 '10 at 06:50 PM