2

Running the dbcc checkident command in SQL Server Management Studio, trying to reset the identity column. As you can see in the picture below clearly my table exists and the schema is the default dbo. But when attempt to execute:

dbcc checkident (Article, RESEED, 4);

I get the following response from the query:

Msg 2501, Level 16, State 45, Line 1
Cannot find a table or object with the name "Article". Check the system catalog.

evidence my table exists

This happens for every table in all of my databases. But this one is the specific one I'm trying to use. The table does have data in it. What can I do/check?

Matt Phillips
  • 11,249
  • 10
  • 46
  • 71
  • Does using Quotes help?? dbcc checkident ('dbo.Article', RESEED, 4); And I assume you have the correct database selected? – DaveShaw Feb 04 '11 at 23:47
  • `create table dbo.Article(a int identity(1,1));dbcc checkident (Article, RESEED, 4);` works for me. Are you sure `dbo` is **your** login's default schema, that your login has sufficient permissions to do this and that you have the right database context selected? – Martin Smith Feb 04 '11 at 23:51
  • @Martin- I don't know what you mean by database context selected. I'm new to SQL Server so I'm flying by seat of pants using it. – Matt Phillips Feb 04 '11 at 23:53
  • @DaveShaw no using quotes and just putting `dbo.Article` both fail the same message. It just puts quotes around the name in the error message – Matt Phillips Feb 04 '11 at 23:54
  • @Matt - How are you running this Script? In SSMS? If so do you have `mattsblog` selected in the dropdown list? You can run `use mattsblog;` to be sure that it is in the right context. – Martin Smith Feb 04 '11 at 23:54
  • @Martin I didn't initially but I just tried selecting it from the Object Explorer in SSMS and then executing the command and it still failed same way – Matt Phillips Feb 04 '11 at 23:56
  • I'm not sure what you mean by selecting it from the Object Explorer. Can you try running `SELECT DB_NAME()` in your script window and see what it says? – Martin Smith Feb 04 '11 at 23:59
  • its one column with 'master' in it. So obviously thats why it's not finding the tables. but what do I do to select my table? – Matt Phillips Feb 05 '11 at 00:00

1 Answers1

2

From the comments it seems your script window is running in the context of the master database. You need to change the context to your database either by changing the value in the dropdown or running the below.

use mattsblog;

dbcc checkident (Article, RESEED, 4);

NB: In SSMS each script window represents a different connection. You can look in the status bar to see things like the current database context, user name, and spid for each window.

Martin Smith
  • 438,706
  • 87
  • 741
  • 845