SQL statement used to back up data in a table

Source: Internet
Author: User

Backup of the same database

1. Copy the table structure (source table name: a new table name: B)

The code is as follows: Copy code

Select * into B from a where 1 <> 1

2. Copy table data (source table name: a target table name: B)

The code is as follows: Copy code

Insert into B (a, B, c) select d, e, f from B

Use the following statement

SELECT * into table_bak FROM table

You can back up data in a table to table_bak without having to re-create table_bak. Table_bak is automatically generated.

From one database to another

Statement format: insert into database name. Framework name. Table name (column name) select (column name) from database name. Framework name. Table name where condition

For example:

The code is as follows: Copy code

Insert into MyEmp. dbo. tjdjb (yybh) select yybh from MyCmd. dbo. tjdjb where djrq = '2017-10-15 'and yybh = '11'

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.