# Keys

A key is an attribute of the relation. There are several types of keys:

* **superkey**
  * K is a superkey of R if values of K are sufficient to identify a unique tuple of each possible relation r(R)
  * Ex. {ID} and {ID,name} are both superkeys of instructor
* **candidate key**
  * A candidate key is a minimal superkey
  * Ex. {ID} is a candidate key for instructor
* **primary key**
  * One of the candidate keys is selected as a primary key
  * A primary key must uniquely identify a tuple
* **foreign key**
  * A relation R1 may include an attribute that is the primary key of another relation R2; this attribute is called the foreign key from R1 to R2
  * R1 is called the **referencing relation** and R2 is called the **referenced relation**
  * The **foreign key constraint** (or **referential integrity constraint**) requires that the values of the attribute in the referencing relation must appear in at least 1 tuple of the referenced relation

In the university database figure (see previous section), the candidate keys for each relation have been underlined and the arrows denote foreign key dependencies.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vikram-bajaj.gitbook.io/cs-gy-6083-principles-of-database-systems/main-1/the-relational-model-details/keys.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
