Saturday, December 05, 2009

SQL Server 2008 T-SQL: Insert Multiple Rows

 

SQL Server 2008 T-SQL Insert Multiple

In SQL Server 2005, in order to insert 3 rows to a table, you had to run 3 INSERT statements:

insert into Customers (Name, City, Phone) values ('Customer #1', 'Jerusalem', '2343245')

insert into Customers (Name, City, Phone) values ('Customer #2', 'Tel Aviv', '0987345')

insert into Customers (Name, City, Phone) values ('Customer #3', 'Haifa', '275466')

In SQL Server 2008, you can insert multiple rows in a single insert statement that takes  a number of value arrays:

insert into Customers (Name, City, Phone)

values

    ('Customer #1', 'Jerusalem', '2343245'),

    ('Customer #2', 'Tel Aviv', '0987345'),

    ('Customer #3', 'Haifa', '275466')

Also nice...

No comments: