In the process of using SQL Server, we may need to copy the table from one database to another, and today I'll show you how and how to do this. It may be a simple thing for most people, but it is better to record it than to write a good memory. Hope can help the students who need ...
Copy table structure:
First step: First, open and connect to SQL Server, right-click on the source database source_db (source database name), then tap "Write table script" → "Create to" → "New Query Editor window".
Step two: Press "Crtl+a" in the editor generated by the 1th step to select all the contents, then right-click "Copy" (or press "Crtl+c" key).
Step three: Create a new query, then right-paste (or CTRL + V), and change the source_db (source database name) in your code to TARGET_DB (the target database name). Then right-click Execute to execute the code.
Fourth step: Then, you can see the copied table in the table structure of the target database.
Data content replication for tables:
First step: Select the target database target_db, then click "Tasks" → "Import data".
Step two: Go to the SQL Server Import and Export Wizard and follow the instructions.
Step three: Select the data source (source database).
Fourth step: Select target (target database), specify table copy or query.
Fifth step: Select source table and Source view: After setting the source and target tables, click the Edit Map button and select "Enable identity insertion" in the pop-up window. (Otherwise an error will occur later)
Sixth step: Always click "Next" to finalize the operation.
SQL Server copies the tables in the database to another database