--*********************查詢數據庫全部對象**********************************數據庫
--存儲過程
select * from sysobjects where xtype='P' --表值函數 xtype='IF',標量值函數 xtype='FN',聚合函數 xtype='AF'
函數
--*********************批量生成權限操做SQL**********************************spa
--存儲過程
select 'GRANT EXEC ON dbo.['+name+'] TO 數據庫用戶名;' from sysobjects where xtype='P'
--表值函數
--select 'GRANT EXEC ON dbo.['+name+'] TO 數據庫用戶名;' from sysobjects where xtype IN('IF','TF') --表值函數不須要單獨賦予權限
--標量值函數
select 'GRANT EXEC ON dbo.['+name+'] TO 數據庫用戶名;' from sysobjects where xtype='FN'
--聚合函數
select 'GRANT EXEC ON dbo.['+name+'] TO 數據庫用戶名;' from sysobjects where xtype='AF' code
--*********************查詢擁有對象具體操做權限**********************************對象
--查詢用戶是否擁有存儲過程(proc_AddQrcode)權限
SELECT * FROM sys.database_permissions WHERE major_id=OBJECT_ID('dbo.proc_AddQrcode')io
--*********************賦予用戶對象操做權限**********************************object
--賦予存儲過程(proc_AddQrcode)執行權限 給用戶lyx
GRANT EXECUTE ON dbo.proc_AddQrcode TO lyx;select
--賦予標量值函數(f_AddDateByType)執行權限 給用戶lyx
GRANT EXECUTE ON dbo.f_AddDateByType TO lyx;權限
其餘權限:數據
INSERT
DELETE
UPDATE
SELECT
CONNECT
EXECUTE
REFERENCES
TAKE OWNERSHIP
VIEW DEFINITION
ALTER
--*******************************************************
SELECT OBJECT_ID(name),name from sysobjects where xtype='FN' AND OBJECT_ID(name)=855415857
--SELECT OBJECT_ID('pro_DeleteAndCopyHsCase')
SELECT major_id,TB.name,COUNT(DISTINCT TA.type)
FROM sys.database_permissions TA
LEFT JOIN sysobjects TB ON TA.major_id=OBJECT_ID(TB.name)
WHERE TB.xtype='P' --'FN'
GROUP BY major_id,TB.name
HAVING COUNT(DISTINCT TA.type)>1
SELECT * FROM sys.database_permissions WHERE major_id=855415857