Monday, August 6, 2012

Insert Multiple Records Using One Insert Statement - SQL Server

How to insert multiple records using one insert statement(using UNION ALL ) instead of going for individual INSERT statements for each row. Here is the sample:


USE YourDbName

GO

INSERT INTO YourTable(FirstColumn, SecondColumn)

SELECT 'First' ,1

UNION ALL

SELECT 'Second' ,2

UNION ALL

SELECT 'Third' ,3

UNION ALL

SELECT 'Fourth' ,4

UNION ALL

SELECT 'Fifth' ,5

GO

No comments:

Post a Comment