Insert of T-SQL

Source: Internet
Author: User
Tags sql 2008

1. Insert basic syntax:

Insert [into] <Table>

[(<Column list>)]

Values (<data values>) [, (<data values>)] [,... n]

 

2. Insert multiple rows (new feature of SQL 2008)

Insert into sales

(Storecode, ordernumber, orderdate)

Values

('Tst1', 'storder1', '2014/1/123 '),

('Tst1', 'storder2', '2014/1/123 ');

 

3. insert into <Table Name>

(<Column list>)

<SELECT statement>

Note: <Table Name> must exist in the database or be stated in advance.

Use adventureworks2008

Declare @ mytable table

(

Salesorderid int,

Customerid char (5)

);

Insert into @ mytable

Select salesorderid, customerid

From adventureworks2008.sales. salesorderheader

Where salesorderid between 44000 and 44010;

 

Select * From @ mytable;

 

 

 

 

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.