Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I export a table's data into INSERT statements?

How can I export a table from a SQL Server 2000 database to a .sql file as a bunch of INSERT INTO statements?

One of the fields in the table is a Text datatype and holds HTML so doing this by hand would be rather time-consuming.

I have access to SQL Server Management Studio 2008 to access the SQL Server 2000 database.

like image 477
Justin808 Avatar asked Nov 03 '10 01:11

Justin808


People also ask

How do I export SQL data to insert statements?

Right click database >> Tasks >> Generate Scripts. Choose Objects: Select specific database objects >> Select the table you want to export. Set scripting options: Select Save to file then click Advanced. Under advanced >> General Options >> Types of data to script - choose Data only >> Click OK.

How do I export the insert script from toad?

you can generate insert script using toad,write table name in toad and press F4 then right click on table name and select export data and then new window will open ,select export format as insert statement then file path to save,script will be generated at specified path.....


1 Answers

Updating since this Q&A was at the top of the search results when I was looking for the answer.

In MSSQL 2008 R2:

Right Click on database: Tasks -> Generate Scripts...

The Generate and Publish Scripts dialog will pop up. The Intro page is worthless. Click "Next"

Choose "Select Specific database objects" and then select the Table(s) you want to get Inserts for. Click Next and the dialog will advance to the "Set Scripting Options".

Click on Advanced and you should see:

enter image description here

Scroll down the list of Options until you find "Types of data to script". Click on that row and choose "Data Only" from the pull-down. Click "OK". Choose your Save options and click "Next" a few times.

Note - The output also includes the following after every 100 inserts.

  GO
  print 'Processed 200 total records'
like image 134
mobill Avatar answered Sep 30 '22 00:09

mobill