Download CS 338 The Relational Data Model and Relational Database

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Clusterpoint wikipedia , lookup

Database wikipedia , lookup

Data vault modeling wikipedia , lookup

Operational transformation wikipedia , lookup

Versant Object Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Database model wikipedia , lookup

Relational algebra wikipedia , lookup

Relational model wikipedia , lookup

Transcript
CS 338
The Relational Data Model and Relational
Database Constraints
Bojana Bislimovska
Winter 2017
Major research
Outline
• Relational Model concepts
• Relational model constraints
• Update operations, transactions
Relational
Model
Concepts
Major research
Represents a collection of relations
• Relation – a table of values (flat file of records)
 Row (tuple) – represents a record of related data values
 Column (attribute) – specifies how to interpret data values
in each row
• All values in a column are from the same data type
Major research
Domains
Set of atomic values specified by:
• Name – helpful in interpreting its values
• Data type
 Character strings
 Numeric (Integer, Real)
 Date
• Format specifies a domain
Attributes
and
Relations
Major research
Relation schema
• Table description
• Formally, R(A1, A2, ...An) consists of
 Relation name R
 List of attributes A1, A2, ..., An
• Attribute
 Attribute domain
 Attribute names do not repeat in a schema, but a domain may repeat
• Degree (arity) of a relation
Database schema
• A set of relation schemas S={R1, R2,..., Rn}
Relation (relation instance) of a relation schema
• Specifies current content of a relation
Characteristics
of
Relations
Major research
Relation –set of n tuples, where each tuple is an ordered list of m values
• Tuples in a relation have no particular order
• Alternative: Ordering of values in a tuple (attributes in a relation schema) is
unnecessary (at abstract level)
 Correspondence between attributes and values is maintained
 To simplify notation, we will consider ordered attributes in a relation schema
• Flat relation model assumes that values in a tuple are atomic
 Composite and multivalued attributes not allowed (alternative
representations)
 Extensions of this model exist
• NULL values – represent unknown values, or values that do not apply to a
tuple
 Several meanings
 Best to avoid them
Characteristics
of
Relations
Major research
Relation can be interpreted as:
• Assertion
 Each tuple interpeted as a fact (assertion instance)
 Relations represent facts about entities and relationships
• Predicate
 Values in each tuple satisfy the predicate
Relational
Model
Notation
Major research
• Uppercase letters Q, R, S denote relation names
• Corresponding lowercase letters q, r, s denote
corresponding relation states
• Uppercase letters A, B, C, …, H denote attributes
 Attribute A can be qualified with the relation name R to
which it belongs using the dot notation, e.g., R.A
• Lowercase letters t, u, v denote tuples
 Tuple t in a relation r(R) is denoted by t=<v1,v2,…,vm>
 t.Ai, t[Ai] – refer to value vi in t for attribute Ai
 t[Au,Aw,…,Az], t.(Au,Aw,…,Az ) – refer to subtuple of values
corresponding to the specified attributes
Relational
Model
Constraints
Major research
• Inherent model-based constraints (implicit constraints)
 Characteristics of relations
• Schema-based constraints (explicit constraints)
 Directly expressed in the schemas
• Application-based (semantic) constraints (business rules)
 Expressed by the application programs, not in the schemas
• Data dependencies
 Test the goodness of a DB design
Schema
Model
Constraints
Major research
• Domain constraints
 Each attribute value must be an atomic value from the domain
 Variety of data types associate with a domain
• Numeric, characters, booleans, strings, date, time, etc.
• Key constraints
 Superkey specifies a uniqueness constraint
 Key is a superkey with an additional property: removal of any
attribute leaves a set of attributes that is not a superkey
anymore
 Key properties
• Uniqueness
• Minimal superkey
• Time-invariant
 Candidate key –more than one key in the schema
• One of them is a primary key (arbitrary choice), others unique keys
Schema
Model
Constraints
Major research
• Constraints on NULL values
 Whether NULL values are permitted
 If an attribute for a tuple is mapped to NULL, cannot make any
assumptions about the value for that attribute (for that tuple)
• Different interpretations for NULL values
Relational Databases and Relational
Database Schema
Major research
• Relational Database Schema is a set of relation
schemas and a set of integrity constraints
• Relational database state (instance) of the schema is a
set of relation states which satisfy the specified
integrity constraints
• All integrity constraints must be satisfied for the
database to be valid
• Each relational DBMS has a Data Definition Language
(DDL) => SQL
Integrity
Constraints
Major research
Specified on the relational database schema
• Entity integrity constraint
 No primary key value can be NULL
• Referential integrity constraint
 Tuple in one relation that refers to another relation must
refer to an existing tuple in that relation
Integrity
Constraints
Major research
• Referential integrity constraint
 Foreign key
A set of attributes in a relation schema R1 that references
relation R2 if:
• Foreign key attributes have same domains as the primary key
attributes of R2
• Foreign key value for a tuple of a current state of R1 is etiher NULL
or occurs as a primary key value for some tuple in the current state
of R2
R1 - referencing relation, R2 - referenced relation
Foreign key can refer to its own relation
Integrity
Constraints
Major research
Operations
on
Relational
Model
Major research
• Retrievals and updates
 Insert
 Delete
 Update
• Non-violation of integrity constraints
Insert
Operation
Major research
Provides a list of attribute values for a new tuple to be inserted
• All four types of constraints can be violated
• If one or more constraints are violated, insertion is rejected
Delete
Operation
Major research
Deletes tuples from a relation
• Only referential integrity is violated
 Restrict – rejects deletion
 Cascade- attempt to propagate the deletion by deleting referencing tuples
 Set null (set default) - modify referencing attribute values that cause violation
 Combination of the above options
Update
Operation
Major research
Modifies attribute values in a tuple (tuples)
• Update of an attribute that is not a primary key or foreign key
 Usually causes no problems
• Updating a primary/foreign key
 Similar possible constraint violations as with Insert/Delete
Transactions
Major research
Executing program that includes some database operations
• All constraints must be satisfied
 Database in a valid and consistent state at the end of each transaction