DBMNG数据库管理与应用

书籍是全世界的营养品。生活里没有书籍,就好像没有阳光;智慧里没有书籍,就好像鸟儿没有翅膀。
当前位置:首页 > SQLServer > 技术手册

MS SQL 权限设置脚本

EXEC sp_addrolemember N'db_owner', N'db'----将db 设置为 db_owner 角色中的一员
EXEC sp_droprolemember N'db_owner', N'db'----将db 从 db_owner 角色 去除
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO dbs ----给db 赋予 拥有 db_datareader 架构
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO db --- 修改 db_datareader 架构的所有者为db
ALTER AUTHORIZATION ON SCHEMA::[db_ddladmin] TO [db_datareader] ---修改 db_datareader 角色所拥有的架构
--- 赋予 《授予 XX 权限》
GRANT VIEW DEFINITION ON [dbo].[PSYP_DataBaseBackUp] TO [db] --查看
GRANT ALTER ON [dbo].[PSYP_DataBaseBackUp] TO [db] --修改
GRANT TAKE OWNERSHIP ON [dbo].[PSYP_DataBaseBackUp] TO [db] --接管所有权
GRANT CONTROL ON [dbo].[PSYP_DataBaseBackUp] TO [db] --控制权
GRANT EXECUTE ON dbo.[PSYP_DataBaseBackUp] TO db --执行
---赋予 《具有授予XX权限》
---如果直接给 具有授予权限 则 默认给予了XX权限
GRANT VIEW DEFINITION ON [dbo].[PSYP_DataBaseBackUp] TO [db] WITH GRANT OPTION --- --查看权限并具有授予权限
GRANT ALTER ON [dbo].[PSYP_DataBaseBackUp] TO [db] WITH GRANT OPTION 
GRANT TAKE OWNERSHIP ON [dbo].[PSYP_DataBaseBackUp] TO [db] WITH GRANT OPTION 
GRANT CONTROL ON [dbo].[PSYP_DataBaseBackUp] TO [db] WITH GRANT OPTION 
GRANT EXECUTE ON [dbo].[PSYP_DataBaseBackUp] TO [db] WITH GRANT OPTION
----拒绝XX权限
DENY VIEW DEFINITION ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
DENY ALTER ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
DENY TAKE OWNERSHIP ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
DENY CONTROL ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
DENY EXECUTE ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
---收回XX权限
REVOKE VIEW DEFINITION ON [dbo].[PSYP_DataBaseBackUp] TO [db] ---查看定义
REVOKE ALTER ON [dbo].[PSYP_DataBaseBackUp] TO [db] --修改
REVOKE TAKE OWNERSHIP ON [dbo].[PSYP_DataBaseBackUp] TO [db] --接管所有权
REVOKE CONTROL ON [dbo].[PSYP_DataBaseBackUp] TO [db] --控制权
REVOKE EXECUTE ON dbo.[PSYP_DataBaseBackUp] TO db --执行
---收回XX具有授予权限
REVOKE GRANT OPTION FOR VIEW DEFINITION ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
REVOKE GRANT OPTION FOR ALTER ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
REVOKE GRANT OPTION FOR TAKE OWNERSHIP ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
REVOKE GRANT OPTION FOR CONTROL ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE
REVOKE GRANT OPTION FOR EXECUTE ON [dbo].[PSYP_DataBaseBackUp] TO [db] CASCADE

--------给表赋 权限
--- 赋予 《具有授予XX权限》
GRANT INSERT ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT VIEW DEFINITION ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT VIEW CHANGE TRACKING ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT ALTER ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT UPDATE ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT TAKE OWNERSHIP ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT CONTROL ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT DELETE ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT SELECT ON [dbo].[a] TO [db] WITH GRANT OPTION 
GRANT REFERENCES ON [dbo].[a] TO [db] WITH GRANT OPTION 

----------表 和 视图 具有相同的权限
INSERT --插入 
VIEW DEFINITION --查看定义
VIEW CHANGE TRACKING -- 查看更改跟踪
ALTER ---修改
UPDATE ---更新
TAKE OWNERSHIP ---接管所有权
CONTROL ---控制
DELETE ---删除
Select ---选择
REFERENCES --引用
 
----存储过程 具有的权限
VIEW DEFINITION ---查看
ALTER ---修改
TAKE OWNERSHIP ---接管所有权
CONTROL ---控制
EXECUTE ---执行

-----标量函数 的权限
VIEW DEFINITION ---查看定义
ALTER ---修改
TAKE OWNERSHIP ---接管所有权
CONTROL ---控制
REFERENCES ---引用
EXECUTE ---执行 

------表值函数 的权限
VIEW DEFINITION ---查看定义
ALTER ---修改
TAKE OWNERSHIP --接管所有权
CONTROL ---控制
REFERENCES ---引用
SELECT ---选择

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号