SqlServer copy table from database to another database

In the process of using SqlServer, we may need to copy tables from one database to another. Today, I will introduce the specific methods and steps of this operation. It may be a very simple thing for most people, but it is still necessary to record it. A good memory is not as good as a bad pen. Hope it can help students in need. . .

Copy the table structure:

Step 1: First, open and connect to Sql Server, right-click on the source database Source_db (source database name), and then click "Script Table As" → "CREATE To" → "New Query Editor Window".

Step 2: In the editor generated in step 1, press the "crtl+a" key combination to select all the content, then right-click and "copy" (or press the "crtl+c" key).

Step 3: Create a new query, then right-click to "Paste" (or ctrl+v); as shown in the figure, change the Source_db (source database name) in the code to target_db (target database name). Then right-click "Execute" to execute the code.

Step 4: Then, you can see the copied table in the table structure of the target database.

Copy the data content of the table:

Step 1: Select the target database target_db, and then click "Task" → "Import Data".

Step 2: Enter the "SQL Server Import and Export Wizard" and operate according to the prompt steps.

Step 3: Select the data source (source database).

Step 4: Select the target (target database), specify table replication or query.

Step 5: Select the source table and source view: After setting the source table and target table, click the "Edit Mapping" button, and select "Enable Identity Insertion" in the pop-up window. (otherwise there will be an error later)

Step 6: Keep clicking "Next" until the final operation is completed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324792131&siteId=291194637