Lecture 1 - Relational Constraints Flashcards
What are relational constraints?
conditions that must hold for all tuples for each relation
i.e. all rows in the table must have a bounded number for each column
How many fundamental constraints is there?
3
What are the 3 fundamental constraints?
- key constraint (unique tuple identification)
- entity integrity constraint (keys never null)
- Referential integrity constraint (interpretation on relationships)
What is a superkey?
a set of attributes containing at least one attribute that uniquely identifies any tuple.
What is a candidate key?
is the minimal superkey; i.e., the set with the smallest number of attributes that uniquely identify tuples.
i.e., the removal of any attribute from K results in K’ that is no longer a superkey
What is a primary key?
If a relation has several candidate keys, one is chosen arbitrarily to be primary key; the rest candidate keys are called secondary keys.It uniquely identifies each row in the table.
Can primary key be null?
NO
Can primary key be a set of attributes?
YES, it becomes a composite primary key
How are PKs represented in a relation schema?
Underlined
What is a REFERENTIAL INTEGRITY CONSTRAINT?
The interpretation of relationships
- foreign keys rules e.g if FK is null, then that FK should not be part of it’s own primary key i.e. not violating the entity integrity constraint
What is an FK?
A key that
t1 is referencing relation (contains FK)
t2 is referenced (contains what FK copies)
t1[FK] references t2[PK] → t1[FK] = t2[PK] or t1[FK] = NULL
What is Semantic Integrity Constraints?
based on application semantics and
cannot be expressed by the relational model…
- e.g., “the maximum number of hours per employee for all projects
he/she works on is 56 hrs per week”. - e.g., ‘each department should control 2 to 5 projects per year .’
- e.g., ‘each department has up to 100 employees’
we require a specific constraint specification language to handle
Whether we need absolute consistency in our database depends on …
appllication and its context. To have asolute consistencies we need an optimal processing algorithm, otherwise we can use suboptimal ones that e.g. flush to db after enough data is processed