Tuesday, January 4, 2011

Invalid object name 'master.dbo.spt_values'. (Microsoft SQL Server, Error: 208)

All the SQL Server DBAs know that we are not supposed to delete anything from the 'master' database or for that matter from any of the system databases. ('model' is an exception though). But how many of us have accidentally deleted something from the master database. Not me....until today. For some unknown reason I ran a query to delete all tables from the master database. I queried the sys.tables to list all tables in master DB and dropped them.
Later I got the following message when I tried to query the user DBs.

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Invalid object name 'master.dbo.spt_values'. (Microsoft SQL Server, Error: 208)

There is one more table that I had dropped which needed to be recreated and that was 'spt_monitor'. Fortunately, I was doing this on in my test environment and did have a backup of the master database. But I still wanted to find out about these tables. So after some quick googling I found some information regarding this tables. I also found out that we can recreate these tables using some scripts that are located in 'Your SQL Server Install Dir/MSSQL/Install' directory. The script is called 'u_tables.sql' and once you use that to create these two tables the error went away. In case the scripts are missing from the directory that I mentioned please send me an email and I will reply back with the scripts.

Things learned today.
  • Always have backups of all DBs.
  • Never delete without taking backups.
  • If you accidentally delete something then do not panic. GoogleMan will come to your rescue.  


  1. Thanks Buddy for the post.


  2. Tried copying a SQL 2014 DB from one server to another. Got message that "Invalid object name 'sys.spt_values'." Tried running u_Tables.SQL. Got this error--
    Creating view 'spt_values'.
    Msg 208, Level 16, State 1, Procedure spt_values, Line 56
    Invalid object name 'sys.spt_values'.
    sp_MS_marksystemobject: Invalid object name 'spt_values'
    Msg 15151, Level 16, State 1, Line 62
    Cannot find the object 'spt_values', because it does not exist or you do not have permission.