Create Trigger Statment

- Membuat tabel baru employees_audit

masukan kode :

CREATE TABLE employees_audit (

    id INT AUTO_INCREMENT PRIMARY KEY,

    employeeNumber INT NOT NULL,

    lastname VARCHAR(50) NOT NULL,

    changedat DATETIME DEFAULT NULL,

    action VARCHAR(50) DEFAULT NULL

);

- Buat Trigger 
CREATE TRIGGER before_employee_update 
    BEFORE UPDATE ON employees
    FOR EACH ROW 
 INSERT INTO employees_audit
 SET action = 'update',
     employeeNumber = OLD.employeeNumber,
     lastname = OLD.lastname,
     changedat = NOW();
- Update Row 
UPDATE employees 
SET 
    lastName = 'Alisa'
WHERE
    employeeNumber = 1056;













Komentar

Postingan populer dari blog ini

Cara mengisi data, mengubah data, dan menghapus data di phpmyadmin