I have a table "person"
id groupId occupation state
1 5 DIRECTOR RETIREMENT
2 5 TEACHER VACATION
3 4 DIRECTOR ACTIVE
I need a trigger that delete new inserted row if it has the same grupiId, the same occupation and state ACTIVE. For example: If I insert a row with groupId 4, function Teacher, state wherever - it's OK. If I insert a row with groupId 4, function Director, state HOLIDAY- it's OK. But If I insert a row with groupId 4, function Director, state ACTIVE it should be deleted after insertion
Don't use a trigger for this. Just use a unique constraint or index:
alter table person add constraint unq_person_groupid_function
unique (groupid, function);
As a note: function
is a poor choice for a column name, because it is a SQL keyword.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.