Wednesday, 6 January 2016

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 questions
Visit Our New Site for HR Interview Questions Answers http://www.interviewboat.com/Company/GetCompany
Sponsored Ads

1 comment:

  1. Thanks for the post!
    My friend was looking for such kind of information for his work related to virtual data rooms comparison.

    ReplyDelete