错误 – 无法找到对象”TABLE”,因为它不存在或您没有权限。

huangapple go评论94阅读模式
英文:

False Error - Cannot find the object "TABLE" because it does not exist or you do not have permissions

问题

我在使用SSMS 2019 (19.0.1)的表设计工具时遇到了这个错误:

> 无法找到对象“xxxxx”,因为它不存在或您没有权限。

过去,我在其他表上进行过类似的操作,都没有问题。我明显有权限,因为为了解决这个错误,我不得不将数据脚本化,删除表格,然后重新创建并重新加载数据。很明显表格是存在的,因为我正在使用SSMS设计工具对其进行更改。

如果我在表格底部添加一列,就不会出现这个错误。只有在两个现有列之间的“顶部”添加时才会出现这个错误。

例如(我们正在添加一个环境变量,它比其他变量更重要):

错误 – 无法找到对象”TABLE”,因为它不存在或您没有权限。

我知道有人说列的顺序无关紧要,但在我们(我公司、同事和我)看来,顺序很重要。所以我们经常右键单击,然后选择“选择前1000行”来查看表格。是的,我知道我们可以创建视图,但那不是我们想要的。

在表格的末尾,我们有所有的安全字段,比如CreatedBy、ModifiedBy、CreatedDate、ModifiedDate等等...在列之后我们没有真正的用户数据字段。我们希望在执行默认查询时能够查看到最相关的数据。

我读过其他帖子,说不能使用“Alter”在两个现有列之间添加新列,但设计工具经常会为您完成这个操作。

所以我的问题是,为什么设计工具在某些表上完全正常地执行,而在其他表上却给出上述误导性的错误?顺便说一下,我们在这些表上使用了AutoAudit (https://github.com/koenmd/AutoAudit/blob/master/AutoAudit%203.30a.sql),它创建了跟踪更改的触发器和视图。是否可能是在表上有视图或触发器导致了这种情况?

英文:

I have been getting this error using the SSMS 2019 (19.0.1) table designer:

> Cannot find the object "xxxxx" because it does not exist or you do not have permissions.

In the past, I have done this with other tables and it works fine. I clearly have permission, because to get around the error, I had to script out the data, drop the table, and recreate it and reload the data. The table clearly exists, because I'm using the SSMS Designer to change it.

If I add a column to the bottom of the table, I don't get this error. Only when adding between two existing columns at the "top" of the column list.

Example (we are adding an environment variable which is really more important than the other variables):

错误 – 无法找到对象”TABLE”,因为它不存在或您没有权限。

I know people say order of the columns doesn't matter, but in our opinion (my company, colleagues and mine), the order is important. So often we do "right click, then "Select Top 1000 Rows" to view the table. And yes, I know we can create views, but that's not what we want.

Towards the end of the table, we have all the security fields, like CreatedBy, ModifiedBy, CreatedDate, ModifiedDate, etc... We don't real user data fields after the columns. We want the most relevant data viewable when doing a default query.

I have read other posts that talk about how you cannot use "Alter" to add a new column between two existing columns, but often times the Designer will do it for you.

So my question is, why does the designer do it perfectly fine on some tables, and why does it give the above misleading error on other tables? By the way, we use AutoAudit (https://github.com/koenmd/AutoAudit/blob/master/AutoAudit%203.30a.sql) on these tables, which creates triggers and views that track who changed what. Could it be that having views or triggers on the table cause this situation?

答案1

得分: 0

上面的Dan Guzman评论帮助了我,他建议从设计器中生成脚本,然后单独运行它。操作如下所示(添加你的列,右键点击,选择“生成更改脚本”):

当我这样做时,我注意到问题出在AutoAudit触发器或相关视图上。

删除表中的AutoAudit组件:[dbo].[My_TableName]
删除表审计DDL
Msg 4902,级别16,状态1,行67
无法找到对象“dbo.My_TableName”,因为它不存在或者您没有权限。
Msg 15248,级别11,状态1,过程sp_rename,行419 [批处理开始行68]
参数@OBJName要么不明确,要么声明的@objtype(OBJECT)是错误的。
Msg 1779,级别16,状态0,行71
表'My_TableName'已经在其上定义了一个主键。
Msg 1750,级别16,状态0,行71
无法创建约束或索引。请参阅前面的错误。
Msg 2714,级别16,状态2,过程My_TableName_Audit_Insert,行1 [批处理开始行77]
数据库中已经存在名为'My_TableName_Audit_Insert'的对象。
Msg 2714,级别16,状态2,过程My_TableName_Audit_Update,行1 [批处理开始行231]
数据库中已经存在名为'My_TableName_Audit_Update'的对象。
Msg 2714,级别16,状态2,过程My_TableName_Audit_Delete,行1 [批处理开始行543]
数据库中已经存在名为'My_TableName_Audit_Delete'的对象。
Msg 2714,级别16,状态2,过程My_TableName_trgAfterUpdate,行1 [批处理开始行682]
数据库中已经存在名为'My_TableName_trgAfterUpdate'的对象。
Msg 3902,级别16,状态1,行697
COMMIT TRANSACTION请求没有相应的BEGIN TRANSACTION。
Msg 2714,级别16,状态5,行700
数据库中已经存在名为'FK_My_TableNameCh_BizTalk_Email_Event'的对象。
Msg 1750,级别16,状态1,行700
无法创建约束或索引。请参阅前面的错误。
Msg 3902,级别16,状态1,行713
COMMIT TRANSACTION请求没有相应的BEGIN TRANSACTION。

我找到了如何使用以下命令删除AutoAudit:

exec [Audit].[pAutoAuditDrop] ...

奇怪的是,在那之后,设计器仍然显示相同的错误。我再次生成了脚本,运行了脚本,它成功执行了更改。所以目前我对结果感到满意,但设计器工具似乎有一些错误。

英文:

The Dan Guzman comment above that helped was to Generate the Script from the Designer, then run it separately. This is done as shown below (add your column, right click, select "Generate Change Script":

错误 – 无法找到对象”TABLE”,因为它不存在或您没有权限。

When I did that, I noticed the issue is with the AutoAudit triggers or related views.

Dropping AutoAudit components from table: [dbo].[My_TableName]
Dropping Table Audit DDL
Msg 4902, Level 16, State 1, Line 67
Cannot find the object "dbo.My_TableName" because it does not exist or you do not have permissions.
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 419 [Batch Start Line 68]
Either the parameter @OBJName is ambiguous or the claimed @objtype (OBJECT) is wrong.
Msg 1779, Level 16, State 0, Line 71
Table 'My_TableName' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 71
Could not create constraint or index. See previous errors.
Msg 2714, Level 16, State 2, Procedure My_TableName_Audit_Insert, Line 1 [Batch Start Line 77]
There is already an object named 'My_TableName_Audit_Insert' in the database.
Msg 2714, Level 16, State 2, Procedure My_TableName_Audit_Update, Line 1 [Batch Start Line 231]
There is already an object named 'My_TableName_Audit_Update' in the database.
Msg 2714, Level 16, State 2, Procedure My_TableName_Audit_Delete, Line 1 [Batch Start Line 543]
There is already an object named 'My_TableName_Audit_Delete' in the database.
Msg 2714, Level 16, State 2, Procedure My_TableName_trgAfterUpdate, Line 1 [Batch Start Line 682]
There is already an object named 'My_TableName_trgAfterUpdate' in the database.
Msg 3902, Level 16, State 1, Line 697
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
Msg 2714, Level 16, State 5, Line 700
There is already an object named 'FK_My_TableNameCh_BizTalk_Email_Event' in the database.
Msg 1750, Level 16, State 1, Line 700
Could not create constraint or index. See previous errors.
Msg 3902, Level 16, State 1, Line 713
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

I figured out how to remove AutoAudit using

> exec [Audit].[pAutoAuditDrop] ...

Strangely enough, after that, the designer still gave the same error. I generated the script again, ran the script, and it ran and did the change. So for now I'm happy with the results, but seems like something buggy with the designer tool.

huangapple
  • 本文由 发表于 2023年8月9日 04:45:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76863100.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定