Exam 2 Flashcards
Popular DBMS systems?
DB2 from IBM Oracle from Oracle Sybase DBMS from SAP SqlServer from Microsoft MySql (Open Source) PostgreSQL (Open Source)
What is a flat file?
Each relation in the database has a flat structure
What is a table?
Each row in the table represents a collection of related data values
What does a tuple represent in a database?
a row
What is an attribute in a database?
a column header
What does a table represent?
a relation
What is a domain?
A domain D is a set of atomic values
What is an atomic value?
Each value in the domain is indivisible
Example domains?
Usa_phone_numbers: the set of 10 digit phone numbers valid in the United States Academic_department_names: The set of academic department names in a university (Computer Science, Economics, Physics)
What is a data type / format?
data type for the domain: Usa_phone_numbers can be declared as a character string of the form (ddd)ddd-dddd, where each d is a numeric (decimal) digit and the first three digits form a valid telephone area code
What is relation schema?
Made up of a relation name R and a list of attributes A1, A2, … An Used to describe a relation Denoted as R
Attribute in relation schema
Each attribute Ai is the name of a role played by a domain D in the relation schema R
Domain in relation schema
D is called the domain of Ai and is denoted by dom(Ai)
what is a degree (arity)
Number of attributes n in the relation schema
Relation of degree 7 example:
STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa) Also sometimes written as… STUDENT(Name: string , Ssn: string , Home_phone: string , Address: string , Office_phone: string , Age: integer , Gpa: real )
What is a Relation state?
A relation state of schema R(A 1 , A 2 , … , A n ) is a set of tuples: r = {t 1 , t 2 , … , t m } Also called relational intention or relation extension:
Cartesian product (x)
Specifies all possible combinations of values from the underlying domains
Current relation state
Only the valid tuples that represent a particular state of the real world
Subset (⊆)
A smaller part of a larger set
Cardinality
Total number of values in a domain
Ordering of tuples in a relation. How does that work?
Elements in a set have no order. Tuples in a mathematical relation have no order However in programming, tuples do have an order There is no preference for one ordering over another
Alternative definition of a relation
Each tuple ti is a mapping from one R to D. D is a union of the attribute domains Tuple is a set of attribute value pairs Tuples list has no order
Self describing data
When a description of each value (like the attribute name) is included in the tuple
Flat relational model
Each value in a tuple is an atomic value that is not divisible Composite and multivalued attributes are now allowed Also called first normal form assumption
Null values
Null can mean value unknown, not available, or does not apply We cannot compare null values. For instance, 2 customers with null addresses do not have the same address! It’s best to avoid null values as much as possible in database design
Assertion
Assertion is a predicate expressing a condition we wish the database to always satisfy Predicate The values in each tuple are values that satisfy the predicate
Closed world assumption
The only true facts in the universe are those present within the extension of the relation
Relational notation
A relation schema R of degree n is denoted by R(A 1 , A 2 , … , A n ). The uppercase letters Q, R, S denote relation names. The lowercase letters q, r, s denote relation states. The letters t, u, v denote tuples.
Constraints
Restrictions on values in the database state Derived from rules in the miniworld
Inherent constraints
Constraints that are inherent in the data model Also called implicit constraints Example: can’t have duplicate tuples
Schema-based constraints
Constraints directly expressed in the schema Also called explicit constraints Domain constraints, key constraints, constraints on ulls, entity integrity, etc
Application-based constraints
Constraints that can’t be expressed in schema but is enforced by the application programs Also called semantic constraints or business rules
Domain constraints
Within each tuple, the value of each attribute must be an atomic value from the domain
Candidate key
A key that can possibly be a primary key in a table Each attribute for a row is unique
Primary Key
The key chosen to maintain uniqueness in a table A candidate key that is used to identify tuples in a relation
Superkey
This is basically a combination of multiple keys that form a primary key Specifies a uniqueness constraint that no two distinct tuples in any state r of R can have the same value for SK Similar to a primary key? Can be used to uniquely identify each tuple
Unique key
Other candidate keys that are not chosen to be a primary key
Relational database schema
A relational database schema S is a set of relation schema and a set of integrity constraints IC The tables and the columns
Relational database state
The rows of a table Also called snapshot or instance
A database that does not obey all its integrity constraints…
A database that does not obey all its integrity constraints is considered not valid Otherwise it is called a valid state Integrity constraints are expected to hold for every valid database state
Entity integrity constraint
No primary key value can be NULL This means we can’t identify some tuples
Referential integrity constraint
Used to maintain the consistency among tuples in two relations For example, a department number in the EMPLOYEE tuple must match an actual department number in the DEPARTMENT table
Foreign key
If a relational schema R1 is a foreign key that references R2, it must have the same domain and must actually refer to a real value
Referencing relation
R1 is the referencing relation and R2 is the referenced relation If this holds, the referential integrity constraint holds
Semantic integrity constraints
Not part of DDL For example: age of child should not exceed age of parent
Constraint specification language
How to specify more general constraints
Trigger and assertions
Can specify some of the constraints in SQL However, more common to check in the actual application code itself
State constraints
Define constraints on a valid state of the database
Transaction constraint
Deal with changes to the database Typically enforced by application programs
Result relation
The answer to a user’s query
Database modification or update
3 basic mechanics: insert, delete, update (modify)
How does an insert work when talking about tuples and schemas?
A new tuple t gets inserted into relation R Can potentially violate constraints Violate domain constraint Attribute value isn’t in domain Violate key constraints New tuple t is already in the relation Violate entity integrity If any part of the primary key is NULL Violate referential integrity If the foreign key is bad The default action is to reject an insert if it violates something
How does a delete work when talking about tuples and schemas?
Removing a tuple Can only violate referential integrity if it’s being referenced from other tuples in the database Several ways to fix this: Restrict Reject the deletion Cascade Propagate the deletion by deleting tuples that reference the tuple being deleted Set null / set default Modify the referencing attribute instead Can cause a violation if part of primary key
How does update work when talking about tuples and schemas?
Change value or one or more attributes in a tuple Only need to check if data type and domain are correct Modifying a primary key can cause problems similar to Delete
What is a transaction?
Executing a database operation Can include any number of retrieval operations or update operations
Relational calculus
Higher level declarative language for specifying relational queries No order of operations to specify how to retrieve the query result
Unary operations (relational algebra)
SELECT and PROJECT operate on single relations
Binary operations (relational algebra)
Operate on two tables by combining related tuples based on join conditions