将数据从一个表复制到另一个表(历史),除了一个非标识列 [英] copy data from one table to another table(history) except one non-identity column
问题描述
考虑一个示例 employee
表,其中包含 empid
、empname
、empsalary
、empdepartment
, empactivity
;和另一个相同列的 employee_history
表,其中一个额外的标识列作为 emphistory_id
.
Consider an example employee
table with empid
, empname
, empsalary
, empdepartment
, empactivity
;
and another employee_history
table of the same columns with one extra identity column as emphistory_id
.
每当我对 employee
表执行任何 update
、delete
或 insert
操作时,employee_history
表也应该更新,但无论是插入、删除还是更新,活动列都应该保存值.
Whenever I perform any update
,delete
or insert
operations on employee
table, employee_history
table should also be updated but activity column should hold value whether it's inserted, deleted or updated.
上面提到的,这些只是示例表.在我的要求中,我有大约 200 列.
Above mentioned, these are just example tables. In my requirement I have around 200 columns.
推荐答案
CREATE TRIGGER new_loaner_added
AFTER INSERT ON total_loaner
FOR EACH ROW
INSERT INTO Logtable (Field )
VALUES (new.Field);
请参考此链接,它将帮助您...
Please Refer this Link it will Help you...
http://www.techonthenet.com/mysql/triggers/after_insert.php
这篇关于将数据从一个表复制到另一个表(历史),除了一个非标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!