简体   繁体   中英

Trigger Postgres Delete

I'm learning SQL, and my teacher gave us that question.

Create a trigger (T_updates_stock_close) to not allow changing the primary key of the inventory close records. Display a message stating the lock and abort the process without allowing the change.

I wanted only one example of how to do it.

Here is the section in the official manuals covering triggers . Here is the part of the manuals covering writing triggers in pl/pgsql . PostgreSQL supports a range of procedural languages, bug pl/pgsql ships with it and is a good choice for simple triggers.

You will want to understand the difference between a "BEFORE" and an "AFTER" trigger, and in this case will want a row-level trigger. If I were you I would start off with a trigger function that just rejects any change on the target table and then step by step work towards your goal.

If that doesn't get you started and you can't understand the manuals take a step back and think whether a computing based course is the correct choice for you. The PostgreSQL manuals are excellent and there are a lot of resources available to learn from nowadays. If you have put in some serious effort and still can't get anywhere then computing might not be for you.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM