CSE Roadmap

Common tier · about 3 hours · 5 parts

Part 2 of 5 · 1 min read

Procedural versus declarative

What separates algebra's step-by-step operators from calculus's description of a result.

Think of two recipes for the same dish. One lists the exact steps to follow in order. The other just describes what the finished plate must look and taste like, leaving the steps up to the cook.

In plain words: relational algebra is procedural. An expression is a sequence of operators, applied in a specific order, describing how to compute the result. Relational calculus is declarative. An expression describes a condition the result must satisfy, without specifying any particular sequence of steps to compute it.

A worked example. Algebra says: take orders, select rows where customer_id = 107. Calculus says: give me every tuple t such that t is in orders and t.customer_id = 107. Both describe the same result; only the second leaves out any notion of steps.

The key lines. No new code here. This part is a contrast in style, not a mechanism.

Procedural, declarative

A procedural language specifies a sequence of steps to compute a result. A declarative language specifies only a condition the result must satisfy, leaving the steps unspecified.

Example: relational algebra is procedural; relational calculus, and SQL itself, are declarative.