很难创建触发器。这是我的代码。我创建了2个表:
CREATE TABLE client_table
(
clientid NUMBER(6) PRIMARY KEY,
lastname varchar2(50) NOT NULL,
firstname varchar2(50) NOT NULL,
password varchar2(20) NOT NULL,
email varchar2(100) NOT NULL,
phoneno NUMBER(12) NOT NULL,
zipcode NUMBER(6) NOT NULL ,
street varchar2(60) NOT NULL,
CHECK (email LIKE '%@%.%')
);
CREATE TABLE location_table
(
zipcode NUMBER(6) PRIMARY KEY,
country varchar2(100) NOT NULL,
region varchar2(60) NOT NULL,
town varchar2(60) NOT NULL
);
我添加了一个约束,以便client_table中的zipcode是外键。
ALTER TABLE client_table
ADD CONSTRAINT clirefzip
FOREIGN KEY(zipcode) REFERENCES location_table(zipcode)
DEFERRABLE INITIALLY DEFERRED;
现在我想添加一个触发器,这样当我从location_table中删除一个位置时,它将从client_table中删除所有与删除位置相同的邮政编码的客户端。所以我尝试这样的事情:
CREATE OR REPLACE TRIGGER location_delete
AFTER DELETE ON location_table
REFERENCING OLD AS old_buffer
FOR EACH ROW
DELETE FROM client_table WHERE zipcode = old_buffer.zipcode;
不幸的是它不起作用。
答案 0 :(得分:0)
Hi there has some syntactical errors in your code. I hope this code works . Thanks
CREATE OR REPLACE TRIGGER location_delete
AFTER DELETE ON location_table
--REFERENCING OLD AS old_buffer
FOR EACH ROW
begin
DELETE FROM client_table WHERE zipcode = zipcode;
end location_trigger;