Reputation: 13
I'm in the process of writing batch loading SQL script and I would like to store the generated primary key of an insert statement into a temp variable and use it to reference the foreign key in the other tables. Any ideas?
I'm doing the following:
Y = INSERT INTO X(.....)
INSERT INTO Z(...,Y,);
Upvotes: 0
Views: 335
Reputation: 22245
I know in SQL Server you can do:
INSERT INTO MyTable ....
SELECT @Foo = @@IDENTITY
INSERT INTO SomeOtherTable(... fk_col ...) VALUES (... @foo ...)
Upvotes: -1