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

Row Constructor

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 we 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
———————————————————————————————————————–

Leave a Reply

Your email address will not be published. Required fields are marked *