VII. SQL Stored Procedures, Triggers, and Rules
VII. SQL Stored Procedures, Triggers, and Rules
SQL Stored
Procedures,
Triggers, and Rules
Automation Nom. Nom. Nom.
In Theory
• We create primary keys and foreign keys to limit our database
to accept only valid data to avoid orphan or duplicate records.
• We can then automate this process by telling the database to
do a set of instructions if these rules are violated.
Creating a Stored Procedure
a.k.a. Custom Function
• Before creating a function, do this:
• Type in the following command, just like pg_dump:
• createlang --username=postgres plpgsql <databasename>
RETURN renter;
END;
$$ LANGUAGE plpgsql;
Creating a Stored Procedure
a.k.a. Custom Function
USING THE FUNCTION: