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' |