SSIS 截断 table 失败;删除成功

SSIS truncate table fails; delete from succeeds

我有一个 SSIS 包,我想在其中清除暂存 table 并重新填充它。我创建了 TRUNCATE TABLE TABLE_NAME 的执行 SQL 任务,该任务因错误而失败:

Table does not exist or you do not have permission

如果我改变任务来执行 DELETE FROM TABLE_NAME 它就像一个魅力。如果我以我正在连接的用户身份登录并执行 TRUNCATE TABLE TABLE_NAME,它也很有效。谁能帮我理解为什么我不能在 SSIS 作业中执行截断,但我可以作为用户执行?因为,我更愿意截断 table 而不是删除。

您可以将错误分为两部分:

  1. Table不存在
  2. 没有权限

所以如果你确定 table 存在 (正如你所说的 DELETE 操作很好),这是一个权限问题,请检查数据库管理员也许您没有权限截断此 table.

中的数据

请注意,TRUNCATE TABLE 需要比 DELETE 操作更多的权限。基于 the official documentation:

The minimum permission required is ALTER on table_name. TRUNCATE TABLE permissions default to the table owner, members of the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles, and are not transferable. However, you can incorporate the TRUNCATE TABLE statement within a module, such as a stored procedure, and grant appropriate permissions to the module using the EXECUTE AS clause.

另一方面,DELETE 操作需要较少的权限。基于 the official documentation:

DELETE permissions are required on the target table. SELECT permissions are also required if the statement contains a WHERE clause.

DELETE permissions default to members of the sysadmin fixed server role, the db_owner and db_datawriter fixed database roles, and the table owner. Members of the sysadmin, db_owner, and the db_securityadmin roles, and the table owner can transfer permissions to other users.