One of the SQL enhancements in SQL Server 2008: Values new use

Source: Internet
Author: User
Tags dname

What's new in SQL Server 2008: You can insert multiple rows using a single insert command.

Create TableDemo_values (PKIDInt Not Null Identity(1,1)Primary Key, dnameNvarchar(20)Null, DCodeNVarchar(30)Null, DdateDatetime Null)Go
--This SQL was only for SQL Server 2008 Insert IntoDemo_values (Dname,dcode,ddate)Values(‘Demoa‘,‘Aaa‘,GETDATE()), (‘Demob‘,‘Bbb‘,GETDATE()), (‘Democ‘,‘Ccc‘,getdate ()), ( demod ' , ddd ' ,getdate ()), ( ' demoe ", ' eee ,getdate ())
--< Span style= "color: #008080;" > (5 row (s) affected)

In addition to inserting more than one line at a time, values has a more subtle use of using a permanent table or temporary table instead of a result set, and does not require a function or table variable. Look at the following example:

--This SQL was only for SQL Server 2008 SelectDname,dcode,ddateFrom(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 the column name, where the column name is used for the SELECT statement.

One of the SQL enhancements in SQL Server 2008: Values new use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.