問題
解決
前幾天看到有人問是否可以方便的獲得SQL SERVER
限
否還有BUG:
IF OBJECTPROPERTY( OBJECT_ID(
DROP PROC usp_getObjectAuthor
GO
/*************************************************************/
/* Created By : leimin */
/* Created On :
/* Description : This stored procedure returns the object permission which
you */
/* GRANT
*/
/**************************************************************/
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=
Set @rowcount=
/**************************************************************/
/* Judge the input parameters
null */
/* then return all objects authorization
/*************************************************************/
if @objectname is null and @username is null
begin
select object_name(a
user_name(a
case b
else
end as Role
case a
when
when
else
end as ProtectType
case a
when
when
when
when
when
when
when
when
when
when
when
when
when
when
else
end as [Action]
user_name(a
from sysprotects a inner join sysusers b on a
where exists (select
where [name]=object_name(a
order by object_name(a
select @rowcount=@@rowcount
if @rowcount=
begin
select @rc=
return @rc
end
end
/**************************************************************/
/* Judge the input parameters
null */
/* then return all objects authorization where relation @username */
/* if the user belong to a group
/**************************************************************/
if @rc=
begin
if not exists(select * from sysusers where [uid]=user_id(@username) and
status<>
begin
select @rc=
return @rc
end
if exists(select
begin
select object_name(a
user_name(a
case b
else
end as Role
case a
when
when
else
end as ProtectType
case a
when
when
when
when
when
when
when
when
when
when
when
when
when
when
else
end as [Action]
user_name(a
from sysprotects a inner join sysusers b on a
where exists (select
where [name]=object_name(a
and ( exists (select
where groupuid=a
or a
order by object_name(a
select @rowcount=@@rowcount
if @rowcount=
begin
select @rc=
print @username+
return @rc
end
end
else
begin
select object_name(a
user_name(a
case b
else
end as Role
case a
when
when
else
end as ProtectType
case a
when
when
when
when
when
when
when
when
when
when
when
when
when
when
else
end as [Action]
user_name(a
from sysprotects a inner join sysusers b on a
where exists (select
where [name]=object_name(a
and a
order by object_name(a
select @rowcount=@@rowcount
if @rowcount=
begin
select @rc=
print @username+
return @rc
end
end
end
/**************************************************************/
/* Judge the input parameters
null */
/* then return one objects authorization */
/**************************************************************/
if @rc=
begin
if not exists(select * from sysobjects where [id]=object_id(@objectname)
and xtype<>
begin
select @rc=
return @rc
end
if @rc=
begin
select object_name(a
user_name(a
case b
else
end as Role
case a
when
when
else
end as ProtectType
case a
when
when
when
when
when
when
when
when
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22087.html