Recently, while working with a customer to help restore their SQL services, I came across an issue I hadn’t seen before and more interestingly, one where little information can be found within the community.
This can be replicated by yourself by attaching or restoring a copy of the master database as a user database. You may never need to do this but just in case you do, don’t be alarmed if ‘corruption’ is found within the user database once it’s attached. The problem was that the customer didn’t have access to their backups. So, my task was to attach all the databases to a recovery instance and execute a DBCC CHECKDB against them. All the user databases were fine and most of the system databases (restored as user databases too) were also fine. All except for the master database. Or so I thought…
I attached the master database as a user database by executing the below TSQL:
GO
( FILENAME = N'E:\SystemDbs\master.mdf' ),
( FILENAME = N'E:\SystemDbs\mastlog.ldf' )
FOR ATTACH
GO
WITH INIT, CHECKSUM
Moving onto performing the restore. To restore the master database as a user database, you’ll need to use RESTORE FILELISTONLY to determine to file locations. This is handy as the ‘WITH MOVE’ clause will be required when restoring the database files to a different location:WITH
MOVE 'master' TO 'C:\Program Files\Microsoft SQL Server\INSTANCELOCATION\MSSQL\DATA\master2.mdf',
MOVE 'mastlog' TO 'C:\Program Files\Microsoft SQL Server\INSTANCELOCATION\MSSQL\DATA\mastlog2.ldf'

Check Catalog Msg 3851, State 1: An invalid row (class=12,depid=0,depsubid=0) was found in the system table sys.syssingleobjrefs (class=12).
Msg 8992, Level 16, State 1, Line 1
Check Catalog Msg 3851, State 1: An invalid row (class=13,depid=1,depsubid=0) was found in the system table sys.syssingleobjrefs (class=13).
Msg 8992, Level 16, State 1, Line 1

