7

Procedural Constructs

Although SQL is a declarative language, it does have procedural features: stored procedures, triggers, and cursors. Stored procedures, or more properly, Persistent Stored Modules (SQL/PSM), give SQL its own 4GL programming language. Triggers are stored procedures attached to one table and controlled by database events such as inserts, updates, and deletes on it. Cursors convert a query, update, or delete statement into a sequential file structure that can be accessed one row at a time.

We will now discuss each one in more detail, but you will find that stored procedures are by far the most useful of the three. Triggers exist because the early SQL Standards did not have declarative referential integrity (DRI) actions. Later ...

Get Joe Celko's SQL for Smarties, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.