简体   繁体   English

触发Postgres删除

[英]Trigger Postgres Delete

I'm learning SQL, and my teacher gave us that question. 我正在学习SQL,而我的老师给了我们这个问题。

Create a trigger (T_updates_stock_close) to not allow changing the primary key of the inventory close records. 创建触发器(T_updates_stock_close)以不允许更改库存结转记录的主键。 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 . 这是手册的一部分,内容涉及在pl / pgsql中编写触发器 PostgreSQL supports a range of procedural languages, bug pl/pgsql ships with it and is a good choice for simple triggers. PostgreSQL支持多种过程语言,它附带有bug pl / pgsql,它是简单触发器的理想选择。

You will want to understand the difference between a "BEFORE" and an "AFTER" trigger, and in this case will want a row-level trigger. 您将需要了解“ BEFORE”触发器和“ AFTER”触发器之间的区别,在这种情况下,将需要一个行级触发器。 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. PostgreSQL手册非常出色,并且现在有很多资源可供学习。 If you have put in some serious effort and still can't get anywhere then computing might not be for you. 如果您付出了很大的努力但仍然无法实现,那么计算可能不适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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