SQL
Foreign Keys
Foreign keys define a column, or set of columns, that refer to a primary key or unique constraint from *another* table. The constraint enforces that the key exists in the other table.  
```sql
CREATE TABLE students (id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE exams (exam_id INTEGER REFERENCES students(id), grade INTEGER);
INSERT INTO students VALUES (1, 'Student 1');
INSERT INTO exams VALUES (1, 10);
INSERT INTO exams VALUES (2, 10);
```  
```console
Constraint Error: Violates foreign key constraint because key "id: 2" does not exist in the referenced table
```  
In order to enforce this property efficiently, an [ART index is automatically created](#docs:sql:indexes) for every foreign key constraint that is defined in the table.  
> **Warning.  ** Indexes have certain limitations that might result in constraints being evaluated too eagerly, leading to constraint errors such as `violates primary key constraint` and `violates unique constraint`. See the [indexes section for more details](#docs:sql:indexes::index-limitations).