views:

285

answers:

5

I'm looking for a way to do something analogous to the MySql dump from SQL Server. I need to be able to pick the tables and export the schema and the data (or I can export the schema via SQL Server Management Studio and export the data separately somehow).

I need this data to be able to turn around and go back into SQL Server so it needs to maintain GUIDs/uniqueidentifiers and other column types.

Does anyone know of a good tool for this?

+1  A: 

BCP can dump your data to a file and in SQL Server Management Studio, right click on the table, and select "script table as" then "create to", then "file..." and it will produce a complete table script.

BCP info
http://blogs.techrepublic.com.com/datacenter/?p=319
http://msdn.microsoft.com/en-us/library/aa174646%28SQL.80%29.aspx

KM
+5  A: 

From the SQL Server Management Studio you can right click on your database and select:

Tasks -> Generate Scripts

Then simply proceed through the wizard. Make sure to set 'Script Data' to TRUE when prompted to choose the script options.

SQL Server 2008

Create Scripts

SQL Server 2008 R2

alt text

Further reading:

Daniel Vassallo
Which version of SqlServer Management Studio is this in? 2005 doesn't seem to have that option.
Jared
@Jared: It does. Check this: http://blogs.msdn.com/robburke/archive/2006/05/30/610803.aspx
Daniel Vassallo
@Daniel, it doesn't have the "Script Data" option
Nathan Koop
@Jared, see this link http://vyaskn.tripod.com/code.htm#inserts
Nathan Koop
+1  A: 

Check out SSMS Tool Pack. It works in Management Studio 2005 and 2008. There is an option to generate insert statements which I've found helpful moving small amounts of data from one system to another.

With this option you will have to script out the DDL separately.

CTKeane
+1  A: 

Just for completeness, I also found this way to do it: Microsoft SqlServer Database Publishing Wizard

Jared
A: 

SqlPubWiz.exe (for me, it's in C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Publishing\1.2>)

Run it with no arguments for a wizard. Give it arguments to run on commandline.

SqlPubWiz.exe script -C "<ConnectionString>" <OutputFile>
Greg