views:

78

answers:

3

Hello, I have a database that I have created using SQL Server Developer 2008.

I want to script it to a file so that it can be recreated by anyone at any time.

Any Ideas?

+1  A: 

You can follow the steps at Pinal's site. Be careful to select all the options you want:

http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/

BobbyShaftoe
Sometimes Sql Server 2008 doesn't script all objects if more than one category is selected: it's safer to do tables, then stored procedures, then views etc.
Stuart Dunkeld
Do you have any source on this? Thanks.
BobbyShaftoe
Just my own personal experience.. it certainly happened regularly, back when I was using scripts to move things around a lot.
Stuart Dunkeld
+1  A: 

To recreate the structure, right-click on the database and use Tasks --> Generate Scripts. Walk your way through the wizard, selecting those objects that you want to have created by your script. This TechNet article will serve as a good starting point for exploring how to do this if the process isn't obvious.

If you need both structure and data, you might want to consider using the Red Gate SQL Packager to script the data.

tvanfosson
Microsoft should really have provided a comprehensive set of tools for that. That being said I do like Red Gate's products.
BobbyShaftoe
Sql Server 2008 has an option to script data..
Stuart Dunkeld
@Stuart -- I looked through the wizard documentation briefly and didn't see that option. What step in the wizard is it? I'd like to update my answer.
tvanfosson
It's in the "Choose Script Options" section, under "Table/View Options"
Stuart Dunkeld
@Stuart - I don't see at MSDN (http://msdn.microsoft.com/en-us/library/ms186472.aspx) and I don't have access to a 2008 instance so I guess I'll leave the answer as stands with your comments to provide context.
tvanfosson
A: 

Try DBSourceTools.
http://dbsourcetools.codeplex.com
Its open source, and will script an entire database
- tables, views, procs and data to disk, and then allow you to re-create that database through a deployment target.
It's specifically designed to help developers get their databases under source code control.

blorkfish