給用戶techuser添加表、視圖、函數權限

一、批量生成所有要授權的表/視圖/函數

--表的權限

select 'grant select, insert, update on '+t.name+' to techuser;' from sys.all_objects t where t.schema_id = 1 and t.type in ('U');


--視圖權限
select 'grant select '+t.name+' to techuser;' from sys.all_objects t where t.schema_id = 1 and t.type in ('V');


--函數權限

select 'grant execute on '+t.name+' to techuser;' from sys.all_objects t where t.schema_id = 1 and t.type in ('FN');

二、執行第一步批量生成的腳本

三、當表/視圖/函數據有新增時,需要生新執行第一、二步

四、改寫成存儲過程,執行存儲過程,自動執行第一、二步,完成授權(等完成)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章