分享
 
 
 

如何获得SQLServer2000中知道对象的权限

王朝mssql·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

问题:如何获得SQL SERVER 2000中知道对象的权限?

解决:

前几天看到有人问是否可以方便的获得SQL SERVER2000指定对象的权限和指定USER的权

限。我写了一个存储过程,可以获得用户和角色的权限。请大家帮忙测试一下。看看是

否还有BUG:-)

IF OBJECTPROPERTY( OBJECT_ID( 'usp_getObjectAuthor' ) , 'IsProcedure' ) =1

DROP PROC usp_getObjectAuthor

GO

/*************************************************************/

/* Created By : leimin */

/* Created On : 29 May 2004 */

/* Description : This stored procedure returns the object permission which

you */

/* GRANT,DENY and REVOKE.

*/

/**************************************************************/

Create proc usp_getObjectAuthor

@objectname sysname = null,

@username sysname = null

as

set nocount on

begin

/**************************************************************/

/* defined the initilization variable */

/**************************************************************/

Declare @rc int

Declare @rowcount int

Declare @groupid int

Set @rc=0

Set @rowcount=0

/**************************************************************/

/* Judge the input parameters ,if @objectname is null and @username is

null */

/* then return all objects authorization. */

/*************************************************************/

if @objectname is null and @username is null

begin

select object_name(a.id) as objectname,

user_name(a.uid) as usename,

case b.issqlrole when 1 then 'Group '

else 'User'

end as Role,

case a.protecttype when 205 then 'Grant'

when 204 then 'Grant'

when 206 then 'Deny'

else 'Revoke'

end as ProtectType,

case a.[action] when 26 then 'REFERENCES'

when 178 then 'CREATE FUNCTION'

when 193 then 'SELECT'

when 195 then 'INSERT'

when 196 then 'DELETE'

when 197 then 'UPDATE'

when 198 then 'CREATE TABLE'

when 203 then 'CREATE DATABASE'

when 207 then 'CREATE VIEW'

when 222 then 'CREATE PROCEDURE'

when 224 then 'EXECUTE'

when 228 then 'BACKUP DATABASE'

when 233 then 'CREATE DEFAULT'

when 235 then 'BACKUP LOG'

when 236 then 'CREATE RULE'

else '0'

end as [Action],

user_name(a.grantor) as Grantor

from sysprotects a inner join sysusers b on a.uid=b.uid

where exists (select 1 from sysobjects

where [name]=object_name(a.id) and xtype 'S' )

order by object_name(a.id)

select @rowcount=@@rowcount

if @rowcount=0

begin

select @rc=-1

print 'There a no user objects in database!'

return @rc

end

end

/**************************************************************/

/* Judge the input parameters ,if @objectname is null and @username is not

null */

/* then return all objects authorization where relation @username */

/* if the user belong to a group ,so we must add the group authorization */

/**************************************************************/

if @rc=0 and @username is not null and @objectname is null

begin

if not exists(select * from sysusers where [uid]=user_id(@username) and

status0)

begin

select @rc=-2

print 'The user name is not include in sysusers table.'

return @rc

end

if exists(select 1 from sysmembers where [memberuid]=user_id(@username))

begin

select object_name(a.id) as objectname,

user_name(a.uid) as usename,

case b.issqlrole when 1 then 'Group '

else 'User'

end as Role,

case a.protecttype when 205 then 'Grant'

when 204 then 'Grant'

when 206 then 'Deny'

else 'Revoke'

end as ProtectType,

case a.[action] when 26 then 'REFERENCES'

when 178 then 'CREATE FUNCTION'

when 193 then 'SELECT'

when 195 then 'INSERT'

when 196 then 'DELETE'

when 197 then 'UPDATE'

when 198 then 'CREATE TABLE'

when 203 then 'CREATE DATABASE'

when 207 then 'CREATE VIEW'

when 222 then 'CREATE PROCEDURE'

when 224 then 'EXECUTE'

when 228 then 'BACKUP DATABASE'

when 233 then 'CREATE DEFAULT'

when 235 then 'BACKUP LOG'

when 236 then 'CREATE RULE'

else '0'

end as [Action],

user_name(a.grantor) as Grantor

from sysprotects a inner join sysusers b on a.uid=b.uid

where exists (select 1 from sysobjects

where [name]=object_name(a.id) and xtype 'S' )

and ( exists (select 1 from sysmembers

where groupuid=a.uid and memberuid=user_id(@username))

or a.uid=user_id(@username))

order by object_name(a.id)

select @rowcount=@@rowcount

if @rowcount=0

begin

select @rc=-3

print @username+' have not any objects authorization.'

return @rc

end

end

else

begin

select object_name(a.id) as objectname,

user_name(a.uid) as usename,

case b.issqlrole when 1 then 'Group '

else 'User'

end as Role,

case a.protecttype when 205 then 'Grant'

when 204 then 'Grant'

when 206 then 'Deny'

else 'Revoke'

end as ProtectType,

case a.[action] when 26 then 'REFERENCES'

when 178 then 'CREATE FUNCTION'

when 193 then 'SELECT'

when 195 then 'INSERT'

when 196 then 'DELETE'

when 197 then 'UPDATE'

when 198 then 'CREATE TABLE'

when 203 then 'CREATE DATABASE'

when 207 then 'CREATE VIEW'

when 222 then 'CREATE PROCEDURE'

when 224 then 'EXECUTE'

when 228 then 'BACKUP DATABASE'

when 233 then 'CREATE DEFAULT'

when 235 then 'BACKUP LOG'

when 236 then 'CREATE RULE'

else '0'

end as [Action],

user_name(a.grantor) as Grantor

from sysprotects a inner join sysusers b on a.uid=b.uid

where exists (select 1 from sysobjects

where [name]=object_name(a.id) and xtype 'S' )

and a.uid=user_id(@username)

order by object_name(a.id)

select @rowcount=@@rowcount

if @rowcount=0

begin

select @rc=-4

print @username+' have not any objects authorization.'

return @rc

end

end

end

/**************************************************************/

/* Judge the input parameters ,if @objectname is not null and @username is

null */

/* then return one objects authorization */

/**************************************************************/

if @rc=0 and @objectname is not null and @username is null

begin

if not exists(select * from sysobjects where [id]=object_id(@objectname)

and xtype'S')

begin

select @rc=-5

return @rc

end

if @rc=0

begin

select object_name(a.id) as objectname,

user_name(a.uid) as usename,

case b.issqlrole when 1 then 'Group '

else 'User'

end as Role,

case a.protecttype when 205 then 'Grant'

when 204 then 'Grant'

when 206 then 'Deny'

else 'Revoke'

end as ProtectType,

case a.[action] when 26 then 'REFERENCES'

when 178 then 'CREATE FUNCTION'

when 193 then 'SELECT'

when 195 then 'INSERT'

when 196 then 'DELETE'

when 197 then 'UPDATE'

when 198 then 'CREATE TABLE'

when 203 then 'CREATE DATABASE'

when 207 the

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有