Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 检查数据库中是否存在存储的进程?_Sql_Sql Server_Database_Stored Procedures - Fatal编程技术网

Sql 检查数据库中是否存在存储的进程?

Sql 检查数据库中是否存在存储的进程?,sql,sql-server,database,stored-procedures,Sql,Sql Server,Database,Stored Procedures,我试图在多个数据库中的存储过程中授予execute priv。问题是此存储过程可能不在某些数据库中。那么,我如何编写一个脚本来检查数据库中是否存在存储的proc,以及是否为用户提供了执行权限呢?有多种方法可以做到这一点: (一) (二) 试试这个: if exists (select 1 from sysobjects where id = object_id('YourProc') and type = 'P') IF EXISTS (SELECT *

我试图在多个数据库中的存储过程中授予execute priv。问题是此存储过程可能不在某些数据库中。那么,我如何编写一个脚本来检查数据库中是否存在存储的proc,以及是否为用户提供了执行权限呢?

有多种方法可以做到这一点:

(一)

(二)

试试这个:

if exists (select 1
      from sysobjects
      where  id = object_id('YourProc')
      and type = 'P')
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
试试这个:

if exists (select 1
      from sysobjects
      where  id = object_id('YourProc')
      and type = 'P')
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