Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_table_privileges

  No additional text.


Syntax

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

 
Last revision 2008RTM
See also

  sp_ddopen (Procedure)
sp_table_privileges_ex (Procedure)
sp_table_privileges_rowset (Procedure)
sp_table_privileges_rowset2 (Procedure)
sp_table_privileges_rowset_rmt (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash