Copy Code code as follows:
Create Table Demo_values
(pkid int NOT null identity (1,1) primary key
, dname Nvarchar () null
, Dcode NVarchar () null
, ddate datetime NULL
)
Go
--this SQL is only for SQL Server 2008
Insert into Demo_values
(dname,dcode,ddate)
Values
(' Demoa ', ' AAA ', GETDATE ()),
(' demob ', ' BBB ', GETDATE ()),
(' Democ ', ' CCC ', GETDATE ()),
(' Demod ', ' DDD ', GETDATE ()),
(' DeMoe ', ' EEE ', GETDATE ())
--(5 row (s) affected)
In addition to being able to insert multiple rows at once, values also have a more ingenious use, representing a result set without using a permanent table or a temporary table, and no function or table variables are required. Look at the following example:
Copy Code code as follows:
--this SQL is only for SQL Server 2008
Select Dname,dcode,ddate
From
(Values
(' Demoa ', ' AAA ', GETDATE ()),
(' demob ', ' BBB ', GETDATE ()),
(' Democ ', ' CCC ', GETDATE ()),
(' Demod ', ' DDD ', GETDATE ()),
(' DeMoe ', ' EEE ', GETDATE ())
)
Demo_values (Dname,dcode,ddate)
--(5 row (s) affected)
/*
Dname Dcode Ddate
Demoa AAA 2010-10-12 20:37:45.500
Demob BBB 2010-10-12 20:37:45.500
Democ CCC 2010-10-12 20:37:45.500
Demod DDD 2010-10-12 20:37:45.500
DeMoe EEE 2010-10-12 20:37:45.500
*/
Note the last line of the statement defines the source name and column name, where the column name is used for the SELECT statement.
I come from Cnblogs invited month 3w@live.cn