Welcome to the Windows community forum and interact with 3 million technical staff. In SQLServer, copy the records in a table to the tables in another database. The existing databases a and B have table1 in database, table 2 in database B needs to copy the records in table 1 to table 2. Different methods are used in different situations: 1.tab
Welcome to the Windows community forum and interact with 3 million technical staff> go to SQLServer and copy the records in a table to the existing database a and database B in another database table. Database a contains table 1, database B has a table table2. now we need to copy the records in table 1 to table 2. Different methods are used in different situations: 1. tab
Welcome to the Windows community forum and interact with 3 million technicians>
Copy the records in a table to another database table in SQLServer
Existing databases a and B. Database a contains table 1, and database B contains table 2.
Now we need to copy the records in table 1 to table 2. Different methods are used in different situations:
1. Table 1 and Table 2 have the same structure.
Use B
Insert into table2 select * from a. dbo. table1
2. The table structures of Table 1 and Table 2 are different.
Use B
Insert into table2 (c1, c2) select c1, c2 from a. dbo. table1
Coolxiaoyi: c1, c2 is the column to be copied.
3. If Table 2 has not been created, you can directly copy the table structure and records of Table 1 to database B.
Use B
Select * into table2 from a. dbo. table1
Coolxiaoyi.
4. Check whether the auto-increment field exists in table 2.
If an auto-increment field exists, an error is returned when the preceding SQL statement is used: only when the column list is used and IDENTITY_INSERT is ON can an explicit value be specified for the ID column in table 'table2.
Coolxiaoyi: you can modify table 2 first, remove the auto-increment identifier, and copy the record before modifying it.
You can also use the SQL statement in step 2 to copy other fields instead of auto-increment fields.