Quiz 1 Flashcards
(44 cards)
Relational Model
Collection of Tables to represent both data and relationships
Tables
Have unique names and fixed set of columns.
AKA “Relations:
Relation
In math terminology, it is a set of tuples
Tuple
In laymens terms it is referred to as a row but can also be described as a sequence (or list) of values.
Attribute
Column
Domain of the attribute
Set of allowed values for an attribute
Atomicity
indivisible
phone numbers and addresses are not atomic
Null value
A special value that is unknown or does not exist.
e.g. in the instructor table, someone might not have a phone number and therefore that field will be left as null for that person.
They can cause difficulties when we access or update databases so we try to eliminate them as much as possible
Relation Schema
A list of attributes and their corresponding domains.
e.g.
Instructor ( ID, name, dept_name, salary)
Department (dept_name, building, budget)
Relation instances
Current values of a relation
Does order of tuples matter?
No
Should two tuples have the same value for all attributes?
No
SuperKey
A set of one or more attributes that uniquely identify a tuple
e.g. ID or Name but ID is better because someone can have the same name
If K is a SuperKey then:
Any superset of K is also a superKey. So if ID is a superkey then any combination of ID and name is also a superkey.
Candidate Key
Special kind of superkey (minimal superkey). Any proper subset of candidate key can’t be a superkey.
e.g. ID and name are possible candidate keys because all other subsets of that key is not a superkey, which in this case is just zero.
Primary Key
A candidate key
Chosen by DB designer
its attributes values are never, or very rarely changed.
e.g. SSN
and ID or unique identitifier might not be good when say two enterprisees merge and then id values may overlap but in our instructor table/relation that is the best we got…
Primary Key Relation Schema
department(dept_name, buildings, budget)
Primary key underlined and before all other attributes
Foreign Key
dept_name is a primary key for the department relation but also exists in the instructor relation so it is therefore referred to as a Foreign key. The department relation is being referenced by the instructor relation.
Referential Integrity
An attribute in referencing relation should be an attribute in referenced relation.
Foreign key constraints are most common form of referential integrity.
Relational Query languages
A language in which a user requests information from a database.
Higher level than standard programming language
Two types:
Procedural:user instructs system to perform a sequence of operations on DB. e.g. Relational Algebgra
Nonprocedural: User describes desired information without giving a procedure. e.g. SQL
Relational Algebra
A set of operations on relations
Parallel to usual Algebra
Usual Algebra examples
Operations: addition, subtraction or multiplication
Input: One or more numbers
Output: A number
e.g. z = 3x + 4y + 10
Relational Algebra examples
Operations: select, project, union, set difference, cartesian product, rename, set intersection, natural join, assignment
Input: one or more relations
Output: A relation (table)
sigma_salary>=85000(instructor)
σ (selection)
Return rows of the input relation that satisfy the predicate.
σ_salary>=85000(instructor)