Friday, March 23, 2012

Rename Files

Is it possible to rename the mdf and log file names?Not while a DB on the server is using those files. (Not that I can
think of off the top of my head anyway.) You'd have to detach the
database (that uses those files), rename the files on the file system
and then reattach those renamed files.
*mike hodgson*
http://sqlnerd.blogspot.com
scott wrote:

>Is it possible to rename the mdf and log file names?
>
>|||Scott,
you could use the following scrip as a template:
USE master;
GO
ALTER DATABASE The_DB MODIFY FILE
(NAME = The_DB_Data,
FILENAME='C:\SQLSVRDB\The_DB_new.mdf');
GO
ALTER DATABASE The_DB SET OFFLINE;
EXEC master..xp_cmdshell 'rename C:\SQLSVRDB\The_DB_old.mdf The_DB_new.mdf';
ALTER DATABASE DB SET ONLINE;
GO
Andrey Odegov
avodeGOV@.yandex.ru
(remove GOV to respond)

No comments:

Post a Comment