Tuesday, November 4, 2008

SQL Server – inserting multiple rows with one statement

This is a nice trick:

INSERT INTO tblTable (rowName1, rowName2)
SELECT 'val1', 'val2'
UNION ALL
SELECT 'val3', 'val4'
UNION ALL
SELECT 'val5', 'val6'

This code will insert 3 rows into the table.

No comments:

Post a Comment