sql触发器无法按预期工作 [英] sql trigger not work as expected
本文介绍了sql触发器无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将一行添加到客户表时,应该:
when one row is added to the customer table it should:
- 复制到另一张称为new_customer表的表
- 删除客户表中的行。
在客户表中只有一个字段,即电话号码。
In customer table has only one field that is Phone number.
此字段应复制到新客户表中,并应从客户表中删除。
This field should be copy into the new customer table and should be deleted from the customer table.
请谁能告诉我此触发器有什么问题.....
please can anyone tell me what's wrong with this trigger.....
CREATE TRIGGER update_cus
ON customer
FOR update AS
IF (COLUMNS_UPDATED() & 1) > 0
BEGIN
INSERT INTO new_customer
(Phone number
)
SELECT 'NEW',
ins.Phone number
FROM inserted ins
SELECT 'OLD',
del.Phone number
FROM deleted del
END
推荐答案
我的猜测
CREATE TRIGGER update_cus
ON customer
FOR update AS
IF EXISTS (SELECT * FROM INSERTED)
BEGIN
INSERT INTO new_customer ([Phone number])
SELECT 'NEW', ins.[Phone number]
FROM inserted ins
DELETE customer WHERE
[Phone number] IN (SELECT [Phone number] FROM deleted)
END
这篇关于sql触发器无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文