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?

1
  • Your question is not clear. Please specify whether you want to create a database, or attach SQL Express to an existing MDF file. Commented Dec 8, 2008 at 15:09

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.