為已授權的資料庫內物件建立T-SQL語法

use northwind
declare @sp sysname
set @sp=’orders’
  declare @permissions nvarchar(max) = “

  select @permissions += dp.state_desc + N’ ‘ + dp.permission_name + N’ ON ‘ +
       quotename(schema_name(o.schema_id)) + N’.’ + quotename(o.name) + N’ TO ‘ +
       quotename(u.name) + N’; ‘ + char(13)
    from sys.database_permissions as dp
    join sys.database_principals as u
      on u.principal_id = dp.grantee_principal_id
    join sys.objects as o
      on o.object_id = dp.major_id
  where dp.class = 1 /* object */
     and dp.minor_id = 0 and o.object_id=object_id(@sp);

  select @permissions

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: