April 18, 2012

sp_dbfixedrolepermission (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_dbfixedrolepermission(nvarchar @rolename)

MetaData:

 create procedure sys.sp_dbfixedrolepermission  
@rolename sysname = NULL
AS
if @rolename is not null
begin
-- VALIDATE GIVEN NAME
if not exists (select * from sys.database_principals where name = @rolename
and principal_id >= 16384 and principal_id <= 16393)
begin
raiserror(15412, -1, -1, @rolename)
return (1)
end

-- RESULT SET FOR SINGLE FIXED-ROLE
select distinct 'DbFixedRole' = u.name, 'Permission' = p.name collate catalog_default
from sys.database_principals u, sys.role_permissions p
where u.name = @rolename and u.principal_id >= 16384 and u.principal_id <= 16393 and
p.type = 'DBR' and p.low > 0 and
((u.principal_id = 16384 and p.number >= 16384 and p.number < 16392) or
(u.principal_id <> 16384 and u.principal_id = p.number))
order by u.name, p.name collate catalog_default
end
else
begin
-- RESULT SET FOR ALL FIXED-ROLES
select distinct 'DbFixedRole' = usr.name, 'Permission' = spv.name collate catalog_default
from sys.database_principals usr, sys.role_permissions spv
where usr.principal_id >= 16384 and usr.principal_id <= 16393 and
spv.type = 'DBR' and spv.low > 0 and
((usr.principal_id = 16384 and spv.number >= 16384 and spv.number < 16392) or
(usr.principal_id <> 16384 and usr.principal_id = spv.number))
order by usr.name, spv.name collate catalog_default
end

return (0) -- sp_dbfixedrolepermission

No comments:

Post a Comment

Total Pageviews