SQL to insert multiple rows of data at a time.

Source: Internet
Author: User

I. The following is a complete example of using SQL programming to insert multiple statements at a time:

Declare   @   Int , @ B   Int
Set   @ = 1
Set   @ B = 20

While   @ <= 20
Begin
Insert   Into Testtb (TID, tvalue) Values ( @ , @ B )
Set   @ = @ + 1
Set   @ B = @ B - 1
End
Select   *   From Testtb
Go

 

Ii. statement format for using insert into Table Name (Field List) Select Value List Union all select Value List:
 

Insert   Into Testtb (TID, tvalue)
Select 94 , 100 Union   All  
Select 72 , 12
Go  


III.
1. Copy data from an existing table to a new table (the table with the same structure as the old table ):
Create   Table Newtb (NID Int , Nvalue Int ) Go
Insert   Into Newtb (NID, nvalue) Select TID, tvalue From Testtb

2. Copy data from an existing table to a new table (the new table does not exist ):

 

SelectTID, tvalueIntoNewtbFromTesttb

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.