Is it possible to insert into two tables at the same time? SQL Server Interview Question
SQL Server Interview Question: Is it possible to insert into two tables at the same time?
In one statement: No.
In one transaction: Yes
BEGIN TRANSACTION
DECLARE @DataID int;
INSERT INTO DataTable (Column1 ...) VALUES (....);
SELECT @DataID = scope_identity();
INSERT INTO LinkTable VALUES (@ObjectID, @DataID);
COMMIT
Click here for more than 300 Sql server Interview questionsIn one statement: No.
In one transaction: Yes
BEGIN TRANSACTION
DECLARE @DataID int;
INSERT INTO DataTable (Column1 ...) VALUES (....);
SELECT @DataID = scope_identity();
INSERT INTO LinkTable VALUES (@ObjectID, @DataID);
COMMIT
Thanks for the post!
ReplyDeleteMy friend was looking for such kind of information for his work related to virtual data rooms comparison.