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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

bkrenzinAuthor Commented:
if the table is another schema.... how do I "see" it so that I can DROP it?
0
Aneesh RetnakaranDatabase AdministratorCommented:
try this way
select * from sys.objects where name like '%spSmartPrinting%update%'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.