Check if stored proc exists in DB?


I am trying to execute scripts of procedures in another database. The problem is this stored procedure exist or not in database. For handling this problem, I wrote following script which checks if stored proc exists in database and if does then provide execute for user?



Try this:


IF EXISTS (SELECT * FROM dbo.sysobjects 
WHERE id = object_id(N'[dbo].[your_procedure_name]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
-- Set privileges here
END


Try this:

if exists (select 1
from sysobjects
where id = object_id('YourProc')
and type = 'P')