SQL - Object already named .... Object does not exist.

SQl Server 2008r2

Have you ever run into a situation where SQL is telling you that there is already an object named “xxx” in the database.

However, when run

DROP TABLE xxx

SQL tells you that the object does not exist?

I have looked in stored procedures, tables, system database.  I cannot find an object named “xxx” anywhere.
bkrenzinAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
try this way
select * from sys.objects where name like '%spSmartPrinting%update%'
0
 
Snarf0001Commented:
Try looking for it in sys.objects.  That will give you the type.

select * from sys.objects where name = 'xxx'
0
 
Scott PletcherSenior DBACommented:
It might also be due to the table's schema.  For example, "user1.xxx" rather than "dbo.xxx".

You might have a different default schema, so you might not "see" the table, but other users do.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
bkrenzinAuthor Commented:
select * from sys.objects where name like '%spSmartPrinting_pre_update%'

returns no records.

select * from sys.objects where name = 'SBM01.._spSmartPrinting_pre_update'

returns no records
0
 
bkrenzinAuthor Commented:
if the table is another schema.... how do I "see" it so that I can DROP it?
0
 
bkrenzinAuthor Commented:
select * from sys.objects where name like '%spSmartPrinting%update%'

returns no records
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Since we don't know the actual name of the sp,

Can you make sure that the database from where you run the query is correct ?
Also can you check for the object in master database
0
 
bkrenzinAuthor Commented:
Correction.... when running

select * from sys.objects where name like '%spSmartPrinting%update%'

on the correct DB (sorry for not paying closer attention).

I get 1 record returned.
2015-03-12-1417.png
0
 
Scott PletcherSenior DBACommented:
That is owned  by 'dbo', so the schema is OK.

Remember that to delete a proc you need to use:
DROP PROCEDURE xxx
rather than
DROP TABLE xxx
:-)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
now you should be able to drop the table
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
@Scott,
Check the image he posted, its a user table not a procedure
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Just out of curiosity, everyone is using sys.objects, how about sys.tables?

IF EXISTS (SELECT name FROM sys.tables WHERE name='your_table_name') 
   DROP TABLE your_table_name
GO

CREATE your_table_name (blah blah blah) 

Open in new window


btw Scott's comment #2 in line is something I fall for all the time, creating an object that gets saved with a schema as something other than dbo, so it sorts way up in the top/bottom of the table list, giving the appearenace it doesn't exist.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
>Just out of curiosity, everyone is using sys.objects, how about sys.tables?
In this case we didn't know that "spSmartPrinting_pre_update" could be a table.
0
 
bkrenzinAuthor Commented:
2015-03-12-1522b.pngOK... do I dropped the table successfully.. but when I cut and paste my SQL statement it still underlines the table name in the script..

So.... i executed the DROP TABLE command at the bottom of the above image and you can see the results in the messages tab.
0
 
bkrenzinAuthor Commented:
2015-03-12-1529c.png
Thought I might check to see if table exists with select statement.

See Results above.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
The table will be created only if you have at least one record on spSmartPrinting table.. You could use the 'Debug' functionality in SSMS to see step by step execution
0
 
Scott PletcherSenior DBACommented:
You should add a statement to see if the table exists, and if it does, to DROP it.

IF OBJECT_ID('SBM01.._spSmartPrinting_pre_update') IS NOT NULL
    DROP TABLE SBM01.._spSmartPrinting_pre_update
0
 
bkrenzinAuthor Commented:
Thank You Gents!!!
Really appreciate your help and time this afternoon.

Regards,
Brian
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.