Attaching Database Incorrect name in sys.master_files I have been moving some databases from SQL 2008 to SQL 2012 using detach and attach method.  I correctly map up all the files and the physical and logical names appear correctly in the properties of the database.

However if I run sys.master_files I can see that all my files have been given the same file name in the Name column of the DMV and this is making our alerting system go crazy.

Has anyone seen this before or know how I can fix it?

Thanks
Well, for one, you really shouldn't be moving database files around using detach/attach:


Bad Habits : Using MDF/LDF Files as "Backups"


The problem probably happened because you reused MDF/LDF files for new databases with different names - the files keep the properties of the original database even if the new database has a different name and the files have different filenames/locations.

But this is an easy "problem" to fix:

ALTER DATABASE dbname MODIFY FILE (NAME = N'old_name', NEWNAME = N'new_name');


(Another way to fix it is to stop your alerting system from even looking at this, never mind complaining about it - other than OCD, there is no reason why two different databases can't have the same logical file names - they're unique per database, not per instance.)