触发更新
我在sqlserver中的表(选项卡)上触发了
Create TRIGGER Trig_TabsUp
on Tabs
For UPDATE
AS
insert into tabs_Update select * from deleted
表tabs_update
与选项卡相同,但选项卡中的身份字段不是tabs_update
中的身份,它只是int。它给了我这个错误
更新或删除的行值不会使该行唯一或将多行更改为 2 行
我尝试将标识字段放入表 Tabs_Update 但仍然是相同的错误
i have trigger in sqlserver on table (tabs)
Create TRIGGER Trig_TabsUp
on Tabs
For UPDATE
AS
insert into tabs_Update select * from deleted
the table tabs_update
the same as tabs but the identity field in tabs is not identity in tabs_update
it just int. It gives me this error
the row values updateed or deleted either don't make the row unique or the alter multiple rows 2 rows
i tried to put an identity field to the table Tabs_Update but still the same error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
SET NOCOUNT ON
添加到触发器定义中。Try adding
SET NOCOUNT ON
to your trigger definition.我猜您对 ID 字段有主键或唯一约束。第二次更新同一条记录时会出现此问题。
Sp_help Tabs_update
会告诉您它们是什么。你把 ID 字段设置为 just 和 int 是对的。但是您可能应该添加一个“更新日期时间”字段,并将主键设置为 ID 和更新日期时间的组合。
另外,执行 select * 几乎总是被认为是一个坏主意。如果您添加新字段并忘记添加更新表,您的触发器将会中断。如果您更改字段的顺序,它也会中断。
I'm guessing you have a Primary Key or unique constraint on the ID field. This is problem on the second time you update the same record.
Sp_help Tabs_update
will tell you what they are.You were right to make the ID field just and int. But you should probably add a Update Date Time field and make the primary key a composite of the ID and update Date time.
Also doing select * is almost always considered a bad idea. Your trigger will break if you add a new field and forget to add the update table. It will also break if you change the order of the fields.