INSERT statement in SQL Server 2008

Did you know that you can now insert multiple values in an INSERT statement separated by commas?

Suppose you have a table like this :
create table amex (aid int)
Then this fails in SQL Server 2005, but succeeds in SQL Server 2008 :
insert into amex values (1), (2)

Also, you can use the non-standard syntax to insert values in both SQL Server versions. Instead of using the VALUES keyword, you can replace that with the SELECT keyword. I dont think this works in Sybase ASE or IBM DB2, though..
insert into amex select 1
Advertisements
This entry was posted in SQL 2008. Bookmark the permalink.

One Response to INSERT statement in SQL Server 2008

  1. rajvision says:

    Reblogged this on Rajiv's space and commented:

    insert Employees (ename, Manager_ID) values (‘Sam’,2), (‘Alex’, 2), (‘Deville’, 2)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s