[英]How would I make a trigger that will check a value to make sure that it is the correct value or else it would throw up an error?
DROP TABLE Officer cascade constraints;
CREATE TABLE Officer(
StaffID Number(6) PRIMARY KEY,
FirstName VARCHAR2(16),
MiddleName VARCHAR2(16),
Surname VARCHAR2(16),
Rank VARCHAR2(16),
Department VARCHAR2(16),
Place_Of_Work VARCHAR2(16),
Hire_Date VARCHAR2(16),
Inspector_ID Number(6));
alter table Officer
add constraint Officer_Inspector_ID_FK
foreign key ( Inspector_ID )
references Officer ( StaffID )
on delete set null
;
create sequence Officer_seq start with 100 increment by 1 nomaxvalue;
create trigger Officer_trigger
before insert on Officer
for each row
begin
select Officer_seq.nextval into :new.StaffID from dual;
end;
What I want to do is make it so that if an inspector ID is entered for an officer that doesn't match up to an officer that has the rank of inspector then it will throw an error that states they aren't an inspector & will prompt them to enter a valid ID. 我要做的是,如果输入的检查人员ID与具有检查人员等级的人员不匹配,则会抛出错误,指出他们不是检查人员,并且会提示他们输入有效的ID。
no trigger required 无需触发
What you are describing is a multi-foreign key constraint from Officer(Inspector_id, Inspector_rank) to Officer(Staff_id, rank) 您所描述的是从Officer(Inspector_id,Inspector_rank)到Officer(Staff_id,rank)的多外键约束
you need to add the inspector_rank field to officer table 您需要将inspector_rank字段添加到高级人员表
then you need to link both id and rank to officer together so they are both the same record 那么您需要同时将id和rank链接到高级人员,以便他们都是同一条记录
foreign key (Inspector_id, Inspector_rank) references Officer(Staff_id, rank)
then you need a simple value constraint of inspector_rank CHECK inspector_rank = INSEPECTOR 那么你需要一个简单的值约束inspector_rank CHECK inspector_rank = INSEPECTOR
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.