Sometimes we want to import all the data from one table of a database to another database or to a database on another computer, and for SQL Server there is a way
Here I take SQL Server R2, the database is the Northwind database, for example,
Objective: To export the Orders table of the Northwind database into an INSERT statement.
First step: Select the Northwind database, right-task-Generate script:
Second step: In the "Generate and publish script" in the introduction window, press the "Next" button:
Step three: In the Select Objects window, select Select Specific database objects, expand the table,
Tick the table where you want to generate the INSERT statement, and I've chosen the order form here.
Press the "Next" button:
Fourth step: In the "Set Scripting Options" window that pops up, press the "Advanced" button,
In the "Advanced scripting Options" pop-down drop-down bar to the bottom,
Set the data type to script to data only (data only is export data as INSERT statement, if you export the table structure, select Schema only, select schema and data, both schema and INSERT statements are generated), press the OK button:
Fifth step: In the "Set Scripting Options" window,
"Specify how to save or publish scripts" output type Select "Save script to a specific location",
Tick "Save to File", you can specify a saved path, save as. sql file,
Tick "Save to new Query window", a new query window opens and all INSERT statements are placed in the new query window:
Sixth step: In the "Set Scripting Options" window, press the "Next" button to eject:
Seventh step: In the "Summary" window, press the "Next" button:
Eighth step: In the "Save or Publish Script" window, press the "Finish" button:
A new query window is created automatically, and all the data in the order table is converted into an INSERT statement.
SQL Server database export table all data into INSERT statement