T-SQL inserts multiple rows of data at once

Source: Internet
Author: User

Inserting data into a table using the Insert SELECT

-- Add the data inserted in T1 to T2 (the T2 table must exist, and the order, data type must be consistent with T1) INSERT  into T2 (Username,password)     SELECT  from T1

Use SELECT into to add data from an existing table to a new table

-- Add the data that is queried in T1 to T2 (the T2 table cannot exist.) will be created in execution)SELECT  t1_username, T1_password     into from T1

To insert an identity column:

-- when inserting, the data for the identity column is not allowed to be specified.  -- if you want to insert an identity column, you can create a new identity column: Identity (type, seed, increment) as column SELECTidentity(int 1 1  as t1_id, T1_username, T1_password      into  from T1

Inserting data using UNION merge

--UNION combines different data or query results into a new result set--the effect is the same as the INSERT SELECT, except that the data is handwritten ...INSERTT1 (Username,password)SELECT 'a','123456' UNION    SELECT 'b','123456' UNION    SELECT 'C','123456' UNION    SELECT 'D','123456' UNION    SELECT 'e','123456' UNION    SELECT 'F','123456' 

T-SQL inserts multiple rows of data at once

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.