views:

1310

answers:

2

I've created a database in Visual Studio 2008 in an App_Data folder of a MVC Web Application project. This results in an mdf file for the database that can be explored in the Server Explorer tab. You can create a SQL script for changes you do to the database.

So I'm wondering how you run these sql change scripts to an mdf-file in Visual Studio 2008? Or am I forced to do this via the SQL Management Studio Express application?

+3  A: 

The syntax is:

CREATE DATABASE [databaseName]

This will create a database on the SQL Server you are connected do, creating files with the standard names in the standard location. There are additional options (described on MSDN) that will help you to place the database files elsewhere (including renaming them) if you wish.

To execute this command, you need to connect to SQL server. I recommend SQL Server Management Studio (there's also the free Express Edition).

Of course, you could also use SQLCMD.

Neil Barnwell
+1  A: 

What you can do is create a Database Project* and connect the project to your database. Database Projects can be found under 'Other Project Types/Database' in the new project dialog. If you then place the create script in the Database project you can run it simply by right clicking on the script in Solution Explorer and selecting Run.

*Database Projects are only available in Visual Studio Professional Edition and above.

Martin Brown