12

I cannot find how to generate a script with all the INSERT i have done so far in my database I managed to generate a script for my database itself but not for the data.

How could i do this ? Thanks in advance

  • I use TOAD for this kind of thing. otherwise you could pump you data to a text file, then run some macros to add the surrounding SQL bits. – Randy Apr 18 '12 at 12:48

2 Answers2

25

Try this, using Sql Server Management Studio:

  1. Right click the database
  2. Select Tasks -> Generate Scripts
  3. (Click next if you get the intro screen)
  4. Select "Select specific database objects"
  5. Pick the objects to generate scripts for (tables, stored procedures, etc...)
  6. Click Next, then specify the output filename
  7. This will generate the schemas only. If you want to do data generating scripts as well, click the Advanced button and scroll down to the "Types of data to script" and change it from "Schema only" to "Data only" or "Schema and data"
  8. Click Finish to generate the script
JohnD
  • 14,327
  • 4
  • 40
  • 53
  • if the script is large check out this article for running it http://stackoverflow.com/questions/222442/sql-server-running-large-script-files – Simon_Weaver May 03 '17 at 22:31
1

If you are using SQL Server 2008, you can generate the script for data in an sql server database by setting the Script Data option in Generate script dialog box

For bringing up Generate Scripts dialog do the following. 1. Right click on a database name in server explorer 2. Select Tasks -> Generate Scripts 3. Click next until you reaches script options 4. Under table/view options there is setting "Script Data". Change it to true to generate script for data.

If you version is the one prior to SQL Server 2008, then are many tools available like Sql Compare from RedGate!

Amal Dev
  • 1,938
  • 1
  • 14
  • 26