views:

334

answers:

1

I have an .mdf file with Visual Studio 2008 with one table in it that has numerous columns of various types.

How can I generate the SQL statement that produces this table so that I can alter it and create another similar table? Is there a way to do this without SQL Server?

+2  A: 

And MDF is a whole SQL Server database - not just a single table.

In SQL Server Management Studio, you can open the "Object Explorer" (View -> Object Explorer or press F7) and then select your database, right-click on it, pick "Tasks..." and then "Generate Scripts ....".

This will launch a wizard which allows you to script out all tables, views, stored procs and any object db objects you might have in your database.

If you're interested in just a single table, drill down into your database and then into tables and find your table in the Object Explorer, and then right click on the table. Pick "Script table as...." and then "Create To....." and you can have a CREATE TABLE script for just that single table in a file, a new query window in SSMS, or on the clipboard for your convenience.

As far as I know, you cannot do this inside Visual Studio, however - you will need to use SQL Server Management Studio (or the Express version of it for SQL Server Express databases).

Marc

marc_s