INSERT TRIGGER 问题:“键列信息不足或不正确。太多行受到更新的影响。”

发布于 2024-10-06 07:25:15 字数 943 浏览 1 评论 0原文

我的 TRIGGER 遇到一些问题:

CREATE TRIGGER "tblSettingTable_INSERT"
ON dbo.tblSettingTable
FOR INSERT
    AS

INSERT INTO dbo.tblSettingReportParameter (tableName, columnName, columnCaption)
SELECT   tableName = CAST(OBJECT_NAME(c.object_id) AS varchar(100)),
            columnName = CAST(c.name AS varchar(100)),
            columnCaption = CAST(ex.value AS varchar(100))
FROM        sys.columns c
LEFT OUTER JOIN sys.extended_properties ex
            ON ex.major_id = c.object_id 
            AND ex.minor_id = c.column_id  
            AND ex.name = 'MS_Caption'
INNER JOIN  inserted ON OBJECT_NAME(c.object_id) = inserted.tableName
WHERE      OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0  
         AND OBJECT_NAME(c.object_id) = inserted.tableName

我正在尝试从表中获取一些列属性并将其插入到 dbo.tblSettingReportParameter 中,但我遇到了这个问题:“关键列信息不够或不正确。太多行受到更新的影响。”

我做错了什么?使用 MS-SQL 2008 RS。

谢谢,

斯特凡

I am having some problems with my TRIGGER:

CREATE TRIGGER "tblSettingTable_INSERT"
ON dbo.tblSettingTable
FOR INSERT
    AS

INSERT INTO dbo.tblSettingReportParameter (tableName, columnName, columnCaption)
SELECT   tableName = CAST(OBJECT_NAME(c.object_id) AS varchar(100)),
            columnName = CAST(c.name AS varchar(100)),
            columnCaption = CAST(ex.value AS varchar(100))
FROM        sys.columns c
LEFT OUTER JOIN sys.extended_properties ex
            ON ex.major_id = c.object_id 
            AND ex.minor_id = c.column_id  
            AND ex.name = 'MS_Caption'
INNER JOIN  inserted ON OBJECT_NAME(c.object_id) = inserted.tableName
WHERE      OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0  
         AND OBJECT_NAME(c.object_id) = inserted.tableName

I am trying the get some column properties from a table and INSERT it into dbo.tblSettingReportParameter but I get this thrown at my face: "Key column information is insufficient or incorrect. Too many rows were affected by update."

What am I doing wrong? Using MS-SQL 2008 RS.

Thanks,

Stefan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-10-13 07:25:15

如果您将 SET NOCOUNT ON 添加到触发器,则应该修复此问题。

返回的 xx 行 使 Access 感到困惑(我假设它会根据问题的标签向 SQL Server 发出 INSERT)

Should be fixed if you add SET NOCOUNT ON to the trigger.

The xx rows returned is confusing Access (which I assume issues the INSERT to SQL Server of course based on the tags for the question)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文