Wednesday, October 21, 2009

Moving database file and renaming database file

exec sp_helpdb DatabaseName

datach:

exec sp_detach_db 'MyDatabase', 'true'

attach:

exec sp_attach_db 'MyDatabase',
'C:\Program Files\Microsoft SQL Server\MSSQL\data\MyDatabase_Data.MDF',
'C:\Program Files\Microsoft SQL Server\MSSQL\data_log\MyDatabase_Log.LDF'

Change logical file name:

alter database MyDatabase modify file (name='test', newname='MyDatabase')
alter database MyDatabase modify file (name='test_log', newname='MyDatabase_log')

source: Timothy Chen Allen

No comments: