3. Relational Model - 3marks Flashcards
What is the relational model (background and four basic concepts)?
Background: • Introduced by E.F. Codd in 1970. • Many DBMS products based on this model (but few completely implement it). • Based on sound theoretical foundation with a simple and uniform data structure: the Relation • Based on mathematical set theory. Four basic concepts: • Relations • Domains • Attributes • Tuples
A relation is (informally):
- a set of records
* similar to a table with columns and rows
What is the main construct for representing data in the relational model?
A relation
A Schema is…
- the meta-data, or data describing data
* specified during database design, and is not expected to change frequently
An Instance is
- the data in the database at a particular time
* created during data updates and change frequently
A domain is characterised by….
- a set of atomic values (ie: indivisible) (eg: the domain ‘Name’ has the set { Albert, Anna, …. Zoe }
- it’s specified data type or format
Domain data types of formats could include…
- integers
- real numbers
- fixed or variable length character strings
- date
- time stamp
- currency
- sub-range from a data type, e.g. 1 ≤ Grade ≤ 7
- enumerated data type, e.g. {‘Male’, ‘Female’}
An attribute is linked to a domain in that it is…
• the name of a role played by some domain in the relation named
Does the same attribute name imply the same domain?
• No. Two attributes could be called ‘code’ from different domains: eg: Subject.CODE and Lecturer.CODE.
Does a different attribute name imply a different domain?
• No. a different attribute name does not necessarily imply different domain (Domains for EID and SID can be the same, but the attribute names must differ.
A tuple is…
- n ordered list of n values
- where each value vi (1 i n) is an element of the corresponding domain of attribute Ai or a special value called “null”
- Usually shown as a row in DB.
Relations are sets of tuples. Do they have an order in a database?
- Not mathematically and practically - order is irrelevant.
* However, the physical storage has some partial ordering.
Relational database design is (one sentence) the process of:
• capturing the semantics of an application, and translating it into a relational database schema
What are some consequences of poor relational database design?
- Poor design can lead to redundant information in tuples and update anomalies.
- Can also result in inability to represent information and consequently, loss of information.
- Conceptual modelling, and other formal techniques, can assist a designer in obtaining good design characteristics.
Where are integrity constraints defined?
On the database schema.
What are the four integrity constraints enforced by a DBMS?
- Key (uniqueness) Constraint
- Entity Integrity
- Referential Integrity
- Domain Constraint
Acronym to remember: KERD
Key (aka uniqueness) Constraint implies:
• No two tuples can have the same value for their primary key attributes
Entity Integrity constraints are:
- Primary key values CAN NOT be null.
* In a composite key, NO PART of the KEY can be NULL (eg: store ID and product ID)
Referential Integrity constraints are:
- Foreign key must reference a value which exists
- Tables need to be connected correctly through primary keys and foreign keys.
- No database will have more than one table
Domain Constraints are:
Every attribute in the relational model comes from some domain.
• No value from one domain can be put into another (eg: text in numerical).
• Can not put multiple values (must be atomic)
A Primary Key is:
The attribute or combination of attributes that uniquely identifies a row or record in a relation.
A superkey is:
a combination of attributes that can be uniquely used to identify a database record.
NB: A table might have many super keys.
Minimal Super key (or just minimal key) is:
a superkey with no redundant attributes.
(EG: RegID uniquely identifies a vehicle, ManufacturerName uniquely identifies a manufacturer, to uniquely identify a car you need both it’s Make and Model.
However multiple car manufacturers can be founded in the same year, meaning YearFounded is not a superkey for manufacturer and so cannot be a minimal key. )
A Candidate Key is:
The fields or combination of fields that could be used as a primary key are known as candidate keys or alternate keys.
A Foreign Key is:
an attribute or combination of attributes in a relation whose value match a primary key in another relation.
• The table in which foreign key is created is called a dependent (child) table.
• The table to which foreign key is refers is known as parent table.
Other general ‘structural’ integrity constraints could include:
Semantic Constraints
• “The salary of an employee should not exceed the employee’s supervisor’s
salary”
• “The maximum number of hours that an employee can work on a project is 56”
Transition Constraints
• “The salary of an employee can only increase”
These are often implemented in a constraint specification language
Eg: (SQL3) using triggers and assertions
Why is enforcement of integrity constraints important to a DB?
It ensures that the database remains consistent
If a database is changed or updated, can integrity constraints be violated?
No.