duminică, 16 ianuarie 2011

Exporting MS SQL data as sql scripts

In PhpMyAdmin exporting data to sql statements not to .mdb files or other databases is very straight forward. When I first had to do this with Sql Management Studio I didn't know how at first.
Then I found out.
Basically, what you have to do is this:
1.right click on a database item
2.go to tasks -> generate scripts in the menu that appears

You now have a wizard that will help you generate scripts for the objects you need. You can either generate one script for all the objects in your database(tables, triggers, stored procedures etc) or one script for just some of the object(you choose which) or each object you choose in it's own script. You can either generate these resulting scripts in files or in new query windows. Everything is configurable from the options window(the wizard step with the title "Choose script options").

Here is an example:
I wanted to just script the triggers in a db. Each in it's own file.
In the options window I set "script triggers" to true and in the following wizard form(with the title "Output options") I chose "file per object".

3 comentarii:

  1. Yes, but this is not data, these are just the objects (tables, procedures and so on) :). I personally haven't found a way to generate INSERT commands for the data in the tables.

  2. Hi, Liviu,
    you can generate data from the options by setting the option script to "data only" or "schema and data"

  3. The option is called "Types of data to script". Sorry ...