TSQL - attempt to drop and create says 'object' already exists

SELECT * FROM sysobjects WHERE type = 'P' AND name = 'UNAdmin.unsp_EmployerInfoListViewSelectAdvanced'

returns 0 results

Then I run the following:

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'UNAdmin.unsp_EmployerInfoListViewSelectAdvanced')
	DROP  Procedure  UNAdmin.unsp_EmployerInfoListViewSelectAdvanced

CREATE PROCEDURE UNAdmin.unsp_EmployerInfoListViewSelectAdvanced



Open in new window

And I get:

Msg 2714, Level 16, State 3, Procedure unsp_EmployerInfoListViewSelectAdvanced, Line 102
There is already an object named 'unsp_EmployerInfoListViewSelectAdvanced' in the database.

And my Object Explorer tree for my Stored Procedures looks like this:

tree says it's there

What have I done to screw-up my database?  LOL  : )

Any help would be appreciated.

Tried this:


No luck.

Tried SCRIPTED drop and create...  no luck....
Tom KnowltonWeb developerAsked:
Who is Participating?

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

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.

dsackerContract ERP Admin/ConsultantCommented:
Try this:
IF OBJECT_ID('UNAdmin.unsp_EmployerInfoListViewSelectAdvanced') IS NOT NULL
    DROP PROCEDURE UNAdmin.unsp_EmployerInfoListViewSelectAdvanced
    PRINT 'Dropped procedure UNAdmin.unsp_EmployerInfoListViewSelectAdvanced'

CREATE PROCEDURE UNAdmin.unsp_EmployerInfoListViewSelectAdvanced

Open in new window

Are you getting the message: 'Dropped procedure UNAdmin.unsp_EmployerInfoListViewSelectAdvanced'?

Is your CREATE statement still bombing?
Brian CroweDatabase AdministratorCommented:
sys.objects.name does not include the schema.  That is why you are not dropping the procedure.

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
Scott PletcherSenior DBACommented:
Btw, sysobjects is very much obsolete.  Use:
Tom KnowltonWeb developerAuthor Commented:
Thanks everyone!

Brian was right.  UNAdmin is not part of the name:

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'unsp_EmployerInfoListViewSelectAdvanced')
      DROP  Procedure  UNAdmin.unsp_EmployerInfoListViewSelectAdvanced

Once I made the change above, it worked.
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.