[英]using mysql how to insert rows in audit table?
I am new to mysql, I have two table employee and audit 我是mysql的新手,我有两个表employee和audit
employee Table have 4 columns 员工表有4列
audit Table have 7 columns 审核表有7列
Here , I want to insert 3 rows in audit table if someone add one row in employee table. 在这里,如果有人在员工表中添加一行,我想在审计表中插入3行。 To maintain the history
保持历史
for eg: I made an entry in employee table 例如:我在员工表中输入了一个条目
John | 20,000 | anaylst
Than my audit table will be 比我的审核表
Type | old_value |new_value | date | username
name| |John | 01/04/2015 | dummy1
sal| |20,000 | 01/04/2015 | dummy1
role | |anaylst | 01/04/2015 | dummy1
I am unable to insert rows in audit table. 我无法在审核表中插入行。
Use a trigger. 使用触发器。
https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html https://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html https://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html
See this answer for details: MySQL Triggers insert into another table 有关详细信息,请参见此答案: MySQL触发器插入到另一个表中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.