Quiz 2 Flashcards
Relation (Instance)
A set of tuples, also called records, in which each tuple has the same number of fields as the relation schema. MUST satisfy domain constraints in the relation schema. TABLE denotes Relation in SQL.
Relation Schema
Specifies the domain of each field or column in the relation instance. Describes the column heads for the table.
Students(sid: string, name: string, login: string, age: integer, gpa: real)
Domain Constraint
Essentially the type of the field, in programming language terms, and restricts the values that can appear in the field. The values that appear in a column must be drawn from the domain associated with that column.
SQL to Define a Relation
CREATE TABLE Students ( sid CHAR(20), name CHAR(30) , login CHAR(20) , age INTEGER, gpa REAL ); // Creates a table (relation) named Students with fields sid, name, login, age, and gpa with their appropriate types.
Integrity Constraints
Domain constraints are a type of integrity constraint.
Primary key constraint - a statement that a certain minimal subset of the fields of a relation is a unique identifier for a tuple.
Foreign key constraint - sometimes the information stored in a relation is linked to the information stored in another relation. If one of the relations is modified, the other must be checked, and perhaps modified, to keep the data consistent.
General Constraints - table constraints and assertions that extend domain constraints. i.e. all students must be at least 16 years old.
Referential Integrity
How the DBMS enforces integrity constraints. These are conditions that ensure things such as a primary key constraint or a foreign key constraint are not violated either by their domains or by a mismatch between related fields/values in a relation.
SQL for Relational Database Queries
SELECT *
FROM Students S
WHERE S.age < 18
// Queries all students from student table who are younger than 18.