0

I create a database based on a mdf file. However I want to be able to store the database in a different directory.

I have,

CREATE DATABASE dbname ON (FILENAME = N'C:\sql_data\dbname.mdf')

Thanks in advance.

0

1 Answer 1

1

How you can specifiy a different locations for your database files is explained on the Technet page CREATE DATABASE .

CREATE DATABASE dbname 
ON 
(NAME = dbname_data, FILENAME = 'C:\temp\dbname.mdf')

If you want to do this with an already existing mdf file then you probably need to use FOR ATTACH.

CREATE DATABASE dbname 
ON (FILENAME = 'C:\temp\test\dbname.mdf')
FOR ATTACH;

It will create a new log file for you if you don't specifiy a location for the log file.

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

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.