An action method in SQL Server that copies the records from one table to the table in another database.
Scene
Existing database A and database B, database A has table table1, database B has table table2.
Now to copy the records from the table Table1 to the table2, different ways are used.
Here are the syntax and examples
1. table1 and TABLE2 table structures are the same
Use b inch into * from A.dbo.table1
2. table1 and TABLE2 table structures are not the same
Use b inch into from A.dbo.table1
Note: C1,C2 is the column that needs to be copied.
3. If you have not created a table table2, you can copy the table structure and records of Table1 directly into database b
use * to from A.dbo.table1
Note: One problem with this is that sometimes the primary foreign key relationship cannot replicate the past (for unknown reasons) and you need to set the primary foreign key yourself after executing the SQL statement.
4. Note whether there are self-growing fields in Table2
If you have a self-growing field, you will get an error when using the above SQL statement: You IDENTITY_INSERT
can specify an explicit value for the Identity column in table ' table2 ' only if the column list is used and on.
Note: You can modify the Table2 table first, remove the self-growth logo, copy the record and then modify it back. Or use 2
the SQL statement in, do not copy the self-growing field, copy the other fields.
Replicating data across libraries in SQL Server