Server programming can also mean setting up automated actions (triggers), so that some operations in the database cause some other things to happen as well. For example, you can set up a process where making an offer on some items is automatically reserved to them in the stock table.
So let's create a fruit stock table:
CREATE TABLE fruits_in_stock ( name text PRIMARY KEY, in_stock integer NOT NULL, reserved integer NOT NULL DEFAULT 0, CHECK (in_stock between 0 and 1000 ), CHECK (reserved <= in_stock) );
CHECK constraints make sure that some basic rules are followed: you can't have more than
1000 fruits in stock (they'll probably go bad), you can't have negative stock, and you can't reserve more than what you ...