SQL inserts more than one record at a time

Source: Internet
Author: User

This article describes how to quickly insert multiple data into a data table to meet the needs of SQL statement learning or project testing.

This article is not original, is the re-collation of the original.

If you have the following form,

1, the original way to add records, SQL statements are as follows:

1   Insert INTO city (Code,citycname) VALUES ('TS',' tangshan ');

2, using the Union to perform interpolation operations, SQL statements are as follows:

1    2     select'ZZ','  Zhengzhou  '3    4     Select'HD', ' Handan '

3,sql Server 2008, the SQL statements are as follows:

1 Insert INTO City     (code,citycname)2     values ('XT',' Xingtai '), ('SJZ',' shijiazhuang ');

Above, the query results are as follows:

4, declare the variable, insert multiple records in a single time, the SQL statement is as follows:

1     int 2     set @i=13while      @i<=4    begin 5 Insert INTO City     (code,citycname)6    values (@i,@i)7     set @[email protected]+18     End

The query results are as follows:

SQL inserts more than one record at a time

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.