jump to navigation

SQL Server 2008 new features-Row Constructors March 6, 2008

Posted by fofo in SQL Server 2008.
Tags: ,
trackback

I will try to introduce some new features of SQL Server 2008. One of them is Row Constructors.

With this new feature-enhancement one can insert multiple records in a table using a single INSERT statement.

In the past in order to enter multiple records in a table, we were using multiple insert statements and just changed the values. now we can achieve the same effect with much less trouble. we fire up sql server 2008 and in a new query window we enter the following:

CREATE TABLE [dbo].[Employee](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [FirstName] [varchar](30) NOT NULL,
 [LastName] [varchar](30) NOT NULL,
 [Country] [varchar] (30) NOT NULL,
 [HireDate] [date] NOT NULL,
 CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED ([ID] ASC)
) ON [PRIMARY]

 make sure you use this “create table” snippet in a sql server 2008 environment, otherwise the statement will fail.

we have just created a table. now we are going to enter sample data in it.

we use the following statement insert statement

INSERT INTO Employee (FirstName, LastName,Country,HireDate)
VALUES
 (‘Robbie’, ‘Fowler’,’ USA’,’1/10/2004′),
 (‘Steven’, ‘Gerrard’,’ Ireland’,’10/3/2000′),
 (‘Michael’, ‘Owen’,’ Britain’,’2/4/2002′)

please note that if one of the sql insert statements fails all the insert statement fail and no data is entered in the table.

Comments»

No comments yet — be the first.

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

%d bloggers like this: