2012-11-29 93 views
-1

我想創建一個觸發器,它將在我們從nm_employees表中刪除值時將值輸入到表中terminate_employees。我寫了觸發器,但是我得到了PL語句的編譯錯誤。有任何想法嗎?SQL-PL觸發器編譯錯誤

CREATE TABLE nm_departments(
dept2 varchar(20), 
CONSTRAINT empPK PRIMARY KEY (dept2) 
); 

CREATE TABLE nm_employees(
name varchar(20), 
dept varchar(20), 
CONSTRAINT departments FOREIGN KEY (dept) REFERENCES nm_departments (dept2)ON DELETE  CASCADE 
); 

CREATE TABLE terminated_employees(
te_name varchar(20), 
te_dept varchar(20) 
); 

CREATE OR REPLACE TRIGGER DeleteCustomer 
BEFORE DELETE ON nm_employees 
FOR EACH ROW 
BEGIN 
INSERT INTO terminated_employees (te_name,te_dept) 
VALUES(:Old.te_name, :Old.te_dept); 
END DeleteCustomer; 
+0

的代碼?哪一行代碼出錯?錯誤說的是什麼? (p.s.我們不是通靈者) – Bohemian

+0

除非你有數十億僱員,否則我只是簡單地在員工表中添加一個列'terminated boolean'並將其留在那裏。 – Bohemian

+0

@Bohemian這看起來像我的Oracle語法添加標籤 – 2012-11-29 05:58:32

回答

1

這將編譯,如果你是在* nm_employees *比這個寫觸發器將是你有你使用的數據庫,寫

CREATE TABLE nm_departments(
    dept2 varchar(20), 
    CONSTRAINT empPK PRIMARY KEY (dept2) 
    ); 

CREATE TABLE nm_employees(
name varchar(20), 
dept varchar(20), 
CONSTRAINT departments FOREIGN KEY (dept) REFERENCES nm_departments (dept2)ON DELETE  CASCADE 
); 

CREATE TABLE terminated_employees(
te_name varchar(20), 
te_dept varchar(20) 
); 

CREATE OR REPLACE TRIGGER DeleteCustomer 
BEFORE DELETE ON nm_employees 
FOR EACH ROW 
BEGIN 
INSERT INTO terminated_employees (te_name,te_dept) 
VALUES(:Old.name, :Old.dept); 
END DeleteCustomer;