65.9K
CodeProject 正在变化。 阅读更多。
Home

获取您可以使用并允许您使用的扩展存储过程列表

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.80/5 (23投票s)

2009年7月26日

CPOL

1分钟阅读

viewsIcon

38635

downloadIcon

176

一种简单的方法来获取您可以使用并允许您使用的扩展存储过程列表。

介绍 

您有多少扩展存储过程有权限在您自己的 SQL 查询/存储过程中作为公共资源使用? 这篇简单的文章将向您展示可供常用使用的所有扩展存储过程。

背景  

几个月前,我需要使用 SQL Server 扩展存储过程,在那里我发现了一些无法正确执行某些任务的扩展存储过程。

因此,我尝试获取一个可供您常用使用的所有扩展存储过程的列表。

使用代码 

这是一种非常简单的方法。我只是使用 master 数据库中的 sysobjects syspermissions 系统表。 表定义如下

sysobjects  

包含数据库中创建的每个对象(约束、默认值、日志、规则、存储过程等)的一行。 在 tempdb 中,此表包含每一临时对象的一行。

更多详细信息请参见 此链接

syspermissions

包含有关数据库中用户、组和角色授予和拒绝的权限的信息。 此表存储在每个数据库中。

更多详细信息请参见 此链接

以下是示例脚本:

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Md. Marufuzzaman>
-- Create date: <Create Date,,02/01/2009>
-- Description:    <Description,,>
-- =============================================
--EXEC spGetPUBLIC_EXProcedure

CREATE PROCEDURE [dbo].[spGetPUBLIC_EXProcedure]
AS
BEGIN

    SELECT     TOP (100) PERCENT SystemObject.name AS [Extended storedProcedure]
             , USER_NAME(SystemPermissionObject.grantee) AS [Granted to]

    FROM    master.dbo.sysobjects AS SystemObject
            INNER JOIN master.dbo.syspermissions AS SystemPermissionObject
            ON SystemObject.id = SystemPermissionObject.id

    WHERE   (SystemObject.type = 'X')
    ORDER BY SystemObject.name

END

GO

结论

我希望本文对您有所帮助。 祝您愉快!

历史

  • 2009 年 7 月 26 日:初始发布
© . All rights reserved.