截断表的权限
在 MSSQL 中,我需要授予用户什么权限才能截断表?
我试图授予最小的权限集,但我无法使用 DELETE,因为表非常大,并且我希望操作快速。
What permission do I need to GRANT a user, in MSSQL, in order to be able to truncate a table?
I'm trying to grant the minimal set of permissions, but I can't use DELETE, because the table is very large, and I want the operation to be quick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要 ALTER 权限:请参阅此处<的权限部分/a>.
请注意,您还可以将存储过程与 EXECUTE AS 一起使用,这样运行存储过程的用户甚至不需要被授予 ALTER 权限。
You need the ALTER permission: see the Permissions section here.
Note that you can also use a stored procedure with EXECUTE AS, so that the user running the stored procedure does not need to even be granted the ALTER permission.
您可以创建一个存储过程
并以所有者身份执行
:然后向需要截断该表的任何人授予执行权限:
现在
TheUser
可以截断该表,如下所示:You can create a stored procedure
with execute as owner
:Then grant execution permissions to whoever needs to truncate that table:
Now
TheUser
can truncate the table like:来源
Source
不要授予,隐藏...
SET CONTEXT_INFO
may be毫无疑问更好将正常的 DELETE 与 TRUNCATE TABLE 分开我还没有尝试过这个...
编辑:更改为使用 SET CONTEXT_INFO。
Don't GRANT, hide...
SET CONTEXT_INFO
may beis without any doubt better to separate a normal DELETE from a TRUNCATE TABLEI haven't tried this...
Edit: changed to use SET CONTEXT_INFO.
您可以创建一个仅对一个表以所有者身份执行的存储过程,或对任何表创建一个存储过程:
You can create a stored procedure with execute as owner to only one table or a store procedure to any table: