หลังจากทำความเข้าใจเกี่ยวกับ Trigger แล้วเราก็มาเริ่มเขียนกันเลยครับ
เริ่มแรกก็สร้างตารางก่อนนะครับ
create table Employee(
id int not null auto_increment primary key,
firstname varchar(45) not null,
lastname varchar(45) not null,
salary int unsigned not null)
create table transaction_log(
user_id varchar(15),
description varchar(50))
CREATE TRIGGER myTrigger BEFORE DELETE ON Employee
FOR EACH ROW
BEGIN
INSERT INTO transaction_log values(user(),'Employee delete record');
END
แค่นี้เราก็ได้ Trigger ที่จะคอยบันทึกการลบข้อมูลในตาราง Employee แล้ว
Friday, August 22, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment