Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

MSSQL%20Interview%20Questions%20and%20Answers

Question: How to move database physical files in MS SQL Server?
Answer: If you want to move database physical files to a new location, you can use the "ALTER DATABASE" statements to bring the database offline, and link it to the files at the new location. The following tutorial gives you a good example:

ALTER DATABASE withoutbook SET ONLINE
GO

USE withoutbook
GO

CREATE TABLE Links (Name NVARCHAR(32))
GO

ALTER DATABASE withoutbook SET OFFLINE
GO

Now it is safe to move the database physical files to a new location:

1. Run Windows Explorer
2. Create a new directory: c:tempdata
3. Drag and drop c:tempwithoutbook.mdf to c:tempdata
3. Drag and drop c:tempwithoutbook.mdf to c:tempdata

Go back to the SQL client program and run:

ALTER DATABASE withoutbook
MODIFY FILE (NAME = withoutbookDB,
FILENAME = 'C:tempdatawithoutbookDB.mdf')
GO
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook