Stored procedure does not exist and does not exist

I have a SQL Server 2008 R2 database with a stored procedure that may or may not exist.

If I run sp_help spThing , it returns the string as if it existed (Name: spThing, Owner: dbo, Type: stored procedure).

If I try to create a new stored procedure with the same name, I get the error message "There is already an object with the name" spThing "in the database.

BUT

If I run SELECT OBJECT_ID('dbo.spThing') , it returns NULL.

If I run EXEC spThing , it says: "Could not find the stored procedure" spThing ".

If I run DROP spThing , he says: "It is not possible to refuse the spThing procedure because it does not exist or you do not have permission."

If I run SELECT * FROM sys.objects WHERE name = 'spThing' , I do not get the string.

If I run SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'spThing' , I do not get the line.

All of them were started from the same connection as the administrative user.

Is there a stored procedure?

Edit:

SP itself is a trivial row choice:

 CREATE PROCEDURE spThing @Param int AS BEGIN SELECT strThing FROM tblThing WHERE lngParam = @Param; END 
+4
source share
3 answers

Everything is working fine -

 IF OBJECT_ID ('dbo.spThing') IS NOT NULL DROP PROCEDURE dbo.spThing GO SELECT OBJECT_ID('dbo.spThing') GO CREATE PROCEDURE dbo.spThing @Param INT AS BEGIN SELECT strThing FROM dbo.tblThing WHERE lngParam = @Param END GO SELECT OBJECT_ID('dbo.spThing') 

Output -

 ----------- NULL (1 row(s) affected) ----------- 664283184 (1 row(s) affected) 
+5
source
 IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spThing]') AND TYPE IN (N'P', N'PC')) DROP PROCEDURE [dbo].[spThing]; GO CREATE PROCEDURE [dbo].[spThing] AS BEGIN -- Code here END GO 
+1
source

For my answer, it exists in dbo.spThing, but does not exist in sys.spThing

I have no specific answer:

There are 2 types of storage procedure, 1 for the system, and I for the database object. 1 attempt by paul and devart is to create dbo.spthing.

first, paul says that if SELECT * FROM sys.objects WHERE name = 'spThing' return no row mean does not exist in the system stored procedure, and devart try is created in dbo.Spthing and will return the result.

just wondering if your question is true on this line or not SELECT OBJECT_ID ('dbo.spThing') because it will exist instead of not existing

Further, you ran sp_help spThing and the owner is dbo, so your dbo.spthing exists. but not sys.spthing

0
source

Source: https://habr.com/ru/post/1490864/


All Articles