SQL Server 2008 new features-Row Constructors March 6, 2008Posted by fofo in SQL Server 2008.
Tags: Sql Server, SQL Server 2008
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)
(‘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.