Avatar of bkrenzin
bkrenzin
 asked on

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.
Microsoft SQL Server

Avatar of undefined
Last Comment
bkrenzin

8/22/2022 - Mon
Snarf0001

Try looking for it in sys.objects.  That will give you the type.

select * from sys.objects where name = 'xxx'
Scott Pletcher

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.
bkrenzin

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
bkrenzin

ASKER
if the table is another schema.... how do I "see" it so that I can DROP it?
ASKER CERTIFIED SOLUTION
Aneesh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bkrenzin

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

returns no records
Aneesh

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bkrenzin

ASKER
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
SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Aneesh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Aneesh

@Scott,
Check the image he posted, its a user table not a procedure
Jim Horn

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Aneesh

>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.
bkrenzin

ASKER
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.
bkrenzin

ASKER
2015-03-12-1529c.png
Thought I might check to see if table exists with select statement.

See Results above.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Aneesh

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
Scott Pletcher

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
bkrenzin

ASKER
Thank You Gents!!!
Really appreciate your help and time this afternoon.

Regards,
Brian
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes