So this is syntax I generally struggle to remember but since I perform quite a few restore operations to multiple development/staging servers and I’m quite particular about my neatness, I like to modify the logical file names for the database and log files.  It’s a simple script and it looks like this

ALTER DATABASE [DBNAME]
MODIFY FILE (NAME = Logical_filename1, NEWNAME = Locical_filename2);
GO

ALTER DATABASE [DBNAME]
MODIFY FILE (NAME = Logical_filename1_log, NEWNAME = Logical_filename2_log);
GO

According to Books Online (filespec being the modify file option)

Only one <filespec> property can be changed at a time. NAME must always be specified in the <filespec> to identify the file to be modified.

This is the reason for the two separate statements to modify the logical name of the database file and the log file.

Advertisements