Home » Interview Q & A » Q2. What is Row constructor/Table valued constructor in SQL Server?

Q2. What is Row constructor/Table valued constructor in SQL Server?

Our Categories

Blog Stats

  • 34,224 hits

Calendar

May 2013
M T W T F S S
« Apr   Jun »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Please visit SQLVERSITY.COM for more details.

Row constructors is the new feature introduced in SQL Server 2008 to insert multiple rows by writing a single INSERT statement.
It saves lot of time when you are inserting many records into a table.

Ex:

-- Before SQL Server 2008 – Multiple INSERT statements required.
INSERT INTO dbo.Employee (EmployeeID, EmployeeName)
VALUES (1, 'Chandra')

INSERT INTO dbo.Employee (EmployeeID, EmployeeName)
VALUES (2, 'Sekhar')

INSERT INTO dbo.Employee (EmployeeID, EmployeeName)
VALUES (3, 'Raparthi')

-- SQL Server 2008 and after (Row constructors)
INSERT INTO dbo.Employee (EmployeeID, EmployeeName) -- Single INSERT statement.
VALUES (1, 'Chandra'), -- Row 1
       (2, 'Sekhar'),  -- Row 2
       (3, 'Raparthi') -- Row 3
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: