cust_name, Contact
已更新,则cust_no, Cust_name, Contact, Date
将添加到第二个表格。第二个表将包含两行旧数据和新数据。我的代码无效。任何帮助将受到高度赞赏。
CREATE TRIGGER update_trigger
AFTER UPDATE ON CUSTOMER_info
FOR EACH ROW
BEGIN
IF NEW.cust_name <> OLD.cust_name || NEW.contact <> OLD.contact then
insert into update_log values
( OLD.cust_no,OLD.cust_name, OLD.contact, CURRENT_DATE);
insert into update_log values
( NEW.cust_no,NEW.cust_name, NEW.contact,CURRENT_DATE);
END IF
END
答案 0 :(得分:1)
如果您使用MSSQL,则可以使用该触发器:
CREATE TRIGGER update_trigger
ON CUSTOMER_info
FOR update AS
BEGIN
IF UPDATE (cust_name) OR UPDATE (contact)
BEGIN
INSERT INTO update_log (
cust_no
,Cust_name
,Contact
,Date
)
SELECT cust_no
,cust_name
,contact
,GetDate()
FROM INSERTED
INSERT INTO update_log (
cust_no
,Cust_name
,Contact
,Date
)
SELECT cust_no
,cust_name
,contact
,GetDate()
FROM DELETED
END
END
GO