Row Constructor in SQL-2008
One of the cool features of SQL 2008 is Row Constructor. The
concept ‘Row Constructors in SQL Server 2008’ basically deals with the crux of
multiple inserts performed at one shot. Instead
of having to call multiple inserts, we could just insert multiple rows with a
single TSQL Statement.
The following example
inserts 3 rows into User Table in a single call. Pay
attention to 'VALUES' in the following statement.
You just need to specify one
INSERT keyword and start filling values separated by comma.
INSERT INTO
Product([Name],[ProductSKU],[CreatedDt])
VALUES
('Test Product1',
'CW76548S', '5/12/2008'),
('Test Product2', 'CW98JK76',
6/12/2008'),
('Test Product3', 'CW909876', '7/12/2008')
You can also use Row
Constructors as a DataSource – On the Fly!
Following is the
Example;
SELECT * FROM
(
VALUES
('Test Product1', 'CW76548S', '5/12/2008'),
('Test
Product2', 'CW98JK76', 6/12/2008'),
('Test Product3', 'CW909876',
'7/12/2008')
) Product([Name],[ProductSKU],[CreatedDt])