GRANT https://docs.microsoft.com/zh-cn/sql/t-sql/statements/grant-transact-sql?view=sql-server-ver15
REVOKE https://docs.microsoft.com/zh-cn/sql/t-sql/statements/revoke-transact-sql?view=sql-server-ver15
CREATE USER https://docs.microsoft.com/zh-cn/sql/t-sql/statements/create-user-transact-sql?view=sql-server-ver15
CREATE ROLE https://docs.microsoft.com/zh-cn/sql/t-sql/statements/create-role-transact-sql?view=sql-server-ver15
AUDIT https://docs.microsoft.com/zh-cn/sql/relational-databases/security/auditing/sql-server-audit-database-engine?view=sql-server-ver15
--没有登录名的用户。 不能登录,但可以被授予权限。
--REF:https://docs.microsoft.com/zh-cn/sql/t-sql/statements/create-user-transact-sql?view=sql-server-ver15
CREATE USER U1 WITHOUT LOGIN;
CREATE USER U2 WITHOUT LOGIN;
CREATE USER U3 WITHOUT LOGIN;
CREATE USER U4 WITHOUT LOGIN;
CREATE USER U5 WITHOUT LOGIN;
CREATE USER U6 WITHOUT LOGIN;
CREATE USER U7 WITHOUT LOGIN;
--[例4.1] 把查询Student表权限授给用户U1
GRANT SELECT
ON Student
TO U1;
--[例4.2] 把对Student表和Course表的全部权限授予用户U2和U3
GRANT ALL PRIVILEGES
ON Student
TO U2,U3;
GRANT ALL PRIVILEGES
ON Course
TO U2,U3;
ALL 权限已不再推荐使用,并且只保留用于兼容性目的。它并不表示对实体定义了 ALL 权限。
--[例4.3] 把对表SC的查询权限授予所有用户
GRANT SELECT
ON SC
TO PUBLIC;
--[例4.4] 把查询Student表和修改学生学号的权限授给用户U4
GRANT UPDATE(Sno), SELECT
ON Student
TO U4;
--[例4.5] 把对表SC的INSERT权限授予U5用户,并允许他再将此权限授予其他用户
GRANT INSERT
ON SC
TO U5
WITH GRANT OPTION;
--[例4.6]
GRANT INSERT
ON SC
TO U6
WITH GRANT OPTION;
--[例4.7]
GRANT INSERT
ON SC
TO U7;
AUDIT
ref:https://blog.csdn.net/DBA_Huangzj/article/details/79033953?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
USE Master
GO
--创建名为Audit-Test的服务器审核
--https://blog.csdn.net/DBA_Huangzj/article/details/79033953?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
CREATE SERVER AUDIT [Audit-Test]
TO FILE --以文件形式存储
(
FILEPATH = 'D:\' --注意替换路径为实际路径
,MAXSIZE = 256 MB --每个文件最大256MB
,MAX_ROLLOVER_FILES = 2147483647 --指定文件数目,2147483647为最高值,只有取消选中“无限制”时才可用
,RESERVE_DISK_SPACE = OFF --不预先分配磁盘空间
)
WITH
(
QUEUE_DELAY = 1000 --延时1秒写入
,ON_FAILURE = CONTINUE --如果发生错误,继续进行
)
WHERE object_name = 'sysadmin' ; --只对对象名为sysadmin的活动进行记录
--记得启用审核
ALTER SERVER AUDIT [Audit-Test] WITH (STATE = ON) ;
DROP SERVER AUDIT [Audit-Test]
此命令要求禁用审核。请禁用审核,然后重新运行此命令。
ALTER SERVER AUDIT [Audit-Test] WITH (STATE = OFF) ;
DROP SERVER AUDIT [Audit-Test]
先禁用审核,再删除就可以了,进一步可以删除磁盘里的 审计文件。