国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

如何獲得SQL SERVER2000數據庫指定對象的權限列表?

2024-08-31 00:48:21
字體:
來源:轉載
供稿:網友
前幾天看到有人問是否可以方便的獲得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 @[email protected]@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
status<>0)
 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 @[email protected]@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 @[email protected]@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 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 [id]=object_id(@objectname)
  order by object_name(a.id)

  select @[email protected]@rowcount
  if @rowcount=0
   begin
    select @rc=-6
    print @objectname+' have not grant authorization to any user'
    return @rc
   end
  end
end
/***************************************************************************
*****/
/*  judge the input parameters ,if @objectname is not null  and @username is
not null */
/*  then return one objects authorization by one user    */
/***************************************************************************
*****/
if @rc=0 and @objectname is not null and @username is not null
begin
 if not exists(select * from sysobjects where [id]=object_id(@objectname)
and xtype<>'s')
 begin
  select @rc=-7
  print 'the object name  is not include in sysobjects table.'
  return @rc
 end

 if not exists(select * from sysusers where [uid]=user_id(@username) and
status<>0)
 begin
  select @rc=-8
  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))
  and [id]=object_id(@objectname)
  order by object_name(a.id)

  select @[email protected]@rowcount
  if @rowcount=0
   begin
    select @rc=-9
    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)
  and  [id]=object_id(@objectname)
  order by object_name(a.id)

  select @[email protected]@rowcount
  if @rowcount=0
   begin
    select @rc=-10
    print @username+' have not any objects authorization.'
    return @rc
   end
 end
   end
end
go
exec usp_getobjectauthor



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵阳市| 隆尧县| 平远县| 孙吴县| 淮滨县| 南昌市| 泉州市| 庆城县| 石渠县| 洛川县| 石楼县| 岳阳市| 石屏县| 武清区| 临漳县| 吴桥县| 安康市| 明溪县| 惠来县| 通州市| 兴宁市| 海宁市| 镇坪县| 宜兰县| 东至县| 轮台县| 盖州市| 庆云县| 曲靖市| 云南省| 张家港市| 潼南县| 彭阳县| 承德县| 板桥市| 农安县| 阳新县| 丽江市| 榕江县| 皮山县| 凤山县|