Sql-server – Migrating Database from local .mdf file to SQL Server 2008

migrationsql serversql-server-2008visual studiovisual studio 2010

I'm not sure if I should be asking this here or over at stackoverflow I apologize if it is the latter.

I have been developing an application in Visual Studio 2010 and using it's built in database functionality with a local .mdf file. I have recently gotten access to a SQL Server 2008 installation, but I can't figure out how to migrate the database.

I have gotten Visual Studio to create a SQL script that should migrate the data, but I can't figure out how to actually run it in SQL Server Management Studio.

Any ideas? Ideally I would like to migrate the schema and the data, but I can settle for just the schema.

Best Answer

If you have an appropriate MDF and LDF file you should be able to attach them within Management Studio by right clicking on the databases folder under your server name in Object Explorer and selecting attach database. Alternatively you can use T-SQL to attach your database files - although you may find the GUI easier to do so.

This link will describe how to do so step by step: http://msdn.microsoft.com/en-us/library/ms190209.aspx

Alternatively to run the script Visual Studio gave you, if you right click on the server name and choose new query you can paste the script here and execute it (use F5 to execute) to run the script.