Friday, April 23, 2010

How to find list of ghost records in SQL Server table?

You can switch on trace flag 2514 which will list Ghost records when you run DBCC CHECKTABLE.

dbcc traceon(2514)
DBCC CHECKTABLE (TableName)


Sample output:
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC CHECKTABLE (SQLInv)
DBCC results for 'SQLInv'.
There are 0 rows in 0 pages for object "SQLInv".
Ghost Record count = 0