Not had this happen before, and am at a loss to explain why.
I made a Full backup of a DEV database, preformed some rollout tests, and then wanted to restore the backup
I restored the backup file, saw that the Logical Names were a bit odd (truncated compared to what we normally use) so I tried to ALTER them:
ALTER DATABASE MyDB_DEV MODIFY FILE (NAME = 'MyDB_DEV_dat', NEWNAME = 'MyDB_DEV_data')
ALTER DATABASE MyDB_DEV MODIFY FILE (NAME = 'MyDB_DEV_lo', NEWNAME = 'MyDB_DEV_log')
and got an error that those logical names didn't exist. I checked the names and they were the correct names after all - how can that be?
So I ran the RESTORE again, more carefully! and checking the names as I went.
RESTORE FILELISTONLY FROM DISK =
'F:\MSSQL\MyDB_BACKUP\MyDB_DEV_20160409_161254_Full.BAK'
gave me:
LogicalName PhysicalName Type FileGroupName Size MaxSize FileId CreateLSN DropLSN UniqueId ReadOnlyLSN ReadWriteLSN BackupSizeInBytes SourceBlockSize FileGroupId LogGroupGUID DifferentialBaseLSN DifferentialBaseGUID IsReadOnly IsPresent TDEThumbprint
------------ -------------------------- ---- ------------- ----------- -------------- ------ --------- ------- ------------------------------------ ----------- ------------ ----------------- --------------- ----------- ------------ --------------------- ------------------------------------ ---------- --------- -------------
MyDB_DEV_dat G:\MSSQL\DATA\MyDB_DEV.mdf D PRIMARY 13290700800 35184372080640 1 0 0 00000000-0000-0000-0000-000000000000 0 0 9732620288 512 1 NULL 174823000002546200067 BA7784F1-41FA-48E6-9721-8B77C72C3220 0 1 NULL
MyDB_DEV_lo H:\MSSQL\Log\MyDB_DEV.ldf L NULL 10223878144 35184372080640 2 0 0 00000000-0000-0000-0000-000000000000 0 0 0 512 0 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL
these are the "abbreviated" logical names that I was trying to ALTER. So far so good.
I restored the database:
RESTORE DATABASE MyDB_DEV
FROM DISK = 'F:\MSSQL\MyDB_BACKUP\MyDB_DEV_20160409_161254_Full.BAK'
WITH
REPLACE,
NORECOVERY,
STATS = 10,
MOVE 'MyDB_DEV_dat' TO 'G:\MSSQL\DATA\MyDB_DEV.mdf',
MOVE 'MyDB_DEV_lo' TO 'H:\MSSQL\Log\MyDB_DEV.ldf'
then I checked the logical names:
SELECT
name AS [Logical_name],
physical_name AS [File_Path],
type_desc AS [File_Type],
state_desc AS [State]
FROM sys.master_files
WHERE database_id = DB_ID(N'MyDB_DEV')
which gave me this:
Logical_name File_Path File_Type State
------------ -------------------------- --------- ---------
MyDB_DEV_dat G:\MSSQL\DATA\MyDB_DEV.mdf ROWS RESTORING
MyDB_DEV_lo H:\MSSQL\Log\MyDB_DEV.ldf LOG RESTORING
which is what I was expecting. Then I set RECOVERY on the the database
RESTORE DATABASE MyDB_DEV WITH RECOVERY
and re-ran the Logical Files query and I got this:
Logical_name File_Path File_Type State
------------- -------------------------- --------- ------
MyDB_DEV_data G:\MSSQL\DATA\MyDB_DEV.mdf ROWS ONLINE
MyDB_DEV_log H:\MSSQL\Log\MyDB_DEV.ldf LOG ONLINE
I was expecting to have to use ALTER to make those changes.
How did that happen?
I made the backup, from the same database, just an hour or so ago. I did not used any ALTER commands thereafter, other than when I made the RESTORE.
EDIT: Ignore the following. I now realise that the first backup was made automatically by scheduled task - after I created the database and before I restored content into it
I have got one other FULL backup, shortly after I established the database and that has the logical names:
LogicalName
-----------
MyDB_DEV
MyDB_DEV_log
and they look wrong to me too. I created the DB in SSMS, and it probably gave it those names, but then I realised I needed to Restore the database from a Full Backup of Production (which made the previous Database Creation unnecessary). I would have expected that Restore operation to have changed the Logical Names (from those used by the Production Database) to MyDB_DEV_data and MyDB_DEV_log (because I use a script to do Restored and that has a fixed method of determining the logical names, and that same script was used to generate the Restore command this time, giving me those logical names.
The logical names ARE what I want them to be, but its a mystery to me how they have changed from what is stored in the Backup file - without me explicitly having used an ALTER command