The relational calculus consists of two calculi, the tuple relational calculus and the domain relational calculus, that are part of the relational model for databases and provide a declarative way to specify database queries. The raison d'être of the relational calculus is the formalization of query optimization, which is finding more efficient manners to execute the same query.

The relational calculus is similar to the relational algebra, which is also part of the relational model: While the relational calculus is meant as a declarative language which prescribes no execution order on the subexpressions of a relational calculus expression, the relational algebra is meant as an imperative language: the sub-expressions of a relational algebraic expressions are meant to be executed from left-to-right and inside-out following their nesting.

Per Codd's theorem, the relational algebra and the domain-independent relational calculus are logically equivalent.

## Example

A relational algebra expression might prescribe the following steps to retrieve the phone numbers and names of book stores that supply Some Sample Book:

1. Join book stores and titles over the BookstoreID.
2. Restrict the result of that join to tuples for the book Some Sample Book.
3. Project the result of that restriction over StoreName and StorePhone.

A relational calculus expression would formulate this query in the following descriptive or declarative manner:

Get StoreName and StorePhone for book stores such that there exists a title BK with the same BookstoreID value and with a BookTitle value of Some Sample Book.

## Mathematical properties

This section needs expansion. You can help by adding to it. (November 2021)

The relational algebra and the domain-independent relational calculus are logically equivalent: for any algebraic expression, there is an equivalent expression in the calculus, and vice versa. This result is known as Codd's theorem.

## Purpose

The raison d'être of the relational calculus is the formalization of query optimization. Query optimization consists in determining from a query the most efficient manner (or manners) to execute it. Query optimization can be formalized as translating a relational calculus expression delivering an answer A into efficient relational algebraic expressions delivering the same answer A.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9032184,"math_prob":0.97501236,"size":1847,"snap":"2023-14-2023-23","text_gpt3_token_len":317,"char_repetition_ratio":0.23168747,"word_repetition_ratio":0.09885932,"special_character_ratio":0.16242555,"punctuation_ratio":0.07457627,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97825646,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-05T20:28:06Z\",\"WARC-Record-ID\":\"<urn:uuid:ae1d17aa-bf8f-4ac9-98ab-70026ac2cfa3>\",\"Content-Length\":\"32152\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a8643680-4c88-4f83-ae53-352f181d4097>\",\"WARC-Concurrent-To\":\"<urn:uuid:3ba8efd9-71d0-47b9-a037-8b16af800499>\",\"WARC-IP-Address\":\"13.249.46.212\",\"WARC-Target-URI\":\"https://db0nus869y26v.cloudfront.net/en/Relational_calculus\",\"WARC-Payload-Digest\":\"sha1:EJHFPBXTH5I7YJ2FCNLCITVWO3FEYXOW\",\"WARC-Block-Digest\":\"sha1:DXFFN42SSG7SEV7SGLIA5UQ23J2STEBS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224652161.52_warc_CC-MAIN-20230605185809-20230605215809-00260.warc.gz\"}"}