June 11, 2012

sp_table_privileges (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_table_privileges(nvarchar @table_name
, nvarchar @table_owner
, nvarchar @table_qualifier
, bit @fUsePattern)

MetaData:

   
create procedure sys.sp_table_privileges
(
@table_name nvarchar(384), -- Wildcard pattern matching is supported.
@table_owner nvarchar(384) = null, -- Wildcard pattern matching is supported.
@table_qualifier sysname = null,
@fUsePattern bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
declare @full_table_name nvarchar(769) -- 384 + 1 + 384
declare @table_id int

if @table_qualifier is not null
begin
if db_name() <> @table_qualifier
begin -- If qualifier doesn't match current database
raiserror (15250, -1,-1)
return
end
end

select @full_table_name = isnull(quotename(@table_owner), '') + '.' + isnull(quotename(@table_name), '')
select @table_id = object_id(@full_table_name)

if (@fUsePattern = 1) -- Does the user want it?
begin
if ((isnull(charindex('%', @full_table_name),0) = 0) and
(isnull(charindex('_', @full_table_name),0) = 0) and
(isnull(charindex('[', @full_table_name),0) = 0) and
(@table_id <> 0))
begin
select @fUsePattern = 0 -- not a single wild char, so go the fast way.
end
end

if @fUsePattern = 0
begin
-- -- Debug output, do not remove it.
print '-- -- -- -- -- -- *'
print 'No pattern matching.'
print @fUsePattern
print isnull(@full_table_name, '@full_table_name = null')
print isnull(@table_name, '@table_name = null')
print isnull(@table_owner, '@table_owner = null')
print '-- -- -- -- -- -- *'
--
select
TABLE_QUALIFIER = s_tpo.TABLE_CATALOG,
TABLE_OWNER = s_tpo.TABLE_SCHEMA,
TABLE_NAME = s_tpo.TABLE_NAME,
GRANTOR = s_tpo.GRANTOR,
GRANTEE = s_tpo.GRANTEE,
PRIVILEGE = convert (varchar(32), s_tpo.PRIVILEGE_TYPE),
IS_GRANTABLE = s_tpo.IS_GRANTABLE_STR
from
sys.spt_table_privileges_view s_tpo
where
(@table_name is null or @table_id = s_tpo.object_id) and
(@table_owner is null or schema_id(@table_owner) = s_tpo.schema_id)
order by 2,3,6,5
end
else
begin
-- -- Debug output, do not remove it.
print '-- -- -- -- -- -- *'
print 'THERE IS pattern matching!'
print @fUsePattern
print isnull(@full_table_name, '@full_table_name = null')
print isnull(@table_name, '@table_name = null')
print isnull(@table_owner, '@table_owner = null')
print '-- -- -- -- -- -- *'
--
if @table_name is null
select @table_name = '%'
if @table_owner is null
select @table_owner = '%'

select
TABLE_QUALIFIER = s_tpo.TABLE_CATALOG,
TABLE_OWNER = s_tpo.TABLE_SCHEMA,
TABLE_NAME = s_tpo.TABLE_NAME,
GRANTOR = s_tpo.GRANTOR,
GRANTEE = s_tpo.GRANTEE,
PRIVILEGE = convert (varchar(32), s_tpo.PRIVILEGE_TYPE),
IS_GRANTABLE = s_tpo.IS_GRANTABLE_STR
from
sys.spt_table_privileges_view s_tpo
where
s_tpo.TABLE_NAME like @table_name and
schema_name(s_tpo.schema_id) like @table_owner
order by 2,3,6,5
end

No comments:

Post a Comment

Total Pageviews