June 11, 2012

sp_table_privileges_ex (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_ex(nvarchar @table_server
, nvarchar @table_name
, nvarchar @table_schema
, nvarchar @table_catalog
, bit @fUsePattern)

MetaData:

   
create procedure sys.sp_table_privileges_ex
(
@table_server sysname,
@table_name sysname = null,
@table_schema sysname = null,
@table_catalog sysname = null,
@fUsePattern bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
if (@fUsePattern = 1) -- Does the user want it?
begin
if ((isnull(charindex('%', @table_name),0) = 0) and
(isnull(charindex('_', @table_name),0) = 0) and
(isnull(charindex('[', @table_name),0) = 0) and
(isnull(charindex('%', @table_schema),0) = 0) and
(isnull(charindex('_', @table_schema),0) = 0) and
(isnull(charindex('[', @table_schema),0) = 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(@table_name, '@table_name = null')
print isnull(@table_schema, '@table_schema = null')
print '-- -- -- -- -- -- *'
--
select
TABLE_CAT = rtp.TABLE_CATALOG,
TABLE_SCHEM = rtp.TABLE_SCHEMA,
TABLE_NAME = rtp.TABLE_NAME,
GRANTOR = rtp.GRANTOR,
GRANTEE = rtp.GRANTEE,
PRIVILEGE = rtp.PRIVILEGE_TYPE,
IS_GRANTABLE = case rtp.IS_GRANTABLE
when 1 then 'YES'
when 0 then 'NO'
else null
end
from
sys.fn_remote_table_privileges (@table_server,
@table_catalog,
@table_schema,
@table_name,
NULL,
NULL) rtp
order by 1, 2, 3, 6
end
else
begin
-- -- Debug output, do not remove it.
print '-- -- -- -- -- -- *'
print 'THERE IS pattern matching!'
print @fUsePattern
print isnull(@table_name, '@table_name = null')
print isnull(@table_schema, '@table_schema = null')
print '-- -- -- -- -- -- *'
--
select
TABLE_CAT = rtp.TABLE_CATALOG,
TABLE_SCHEM = rtp.TABLE_SCHEMA,
TABLE_NAME = rtp.TABLE_NAME,
GRANTOR = rtp.GRANTOR,
GRANTEE = rtp.GRANTEE,
PRIVILEGE = rtp.PRIVILEGE_TYPE,
IS_GRANTABLE = case rtp.IS_GRANTABLE
when 1 then 'YES'
when 0 then 'NO'
else null
end
from
sys.fn_remote_table_privileges (@table_server,
@table_catalog,
NULL,
NULL,
NULL,
NULL) rtp
where
(TABLE_SCHEMA like @table_schema or
@table_schema is NULL or
(TABLE_SCHEMA is NULL and @table_schema = N'%')) and
(TABLE_NAME like @table_name or @table_name is NULL)
order by 1, 2, 3, 6
end

No comments:

Post a Comment

Total Pageviews