730 likes | 948 Views
IT 20303. Relational Database Theory. Relational Database Theory. The Relational Theory Ways of working with data Types of “Models” File database model Hierarchical database model Network database model Relational database model. Relational Database Theory. The Relational Theory
E N D
IT 20303 • Relational Database Theory
Relational Database Theory • The Relational Theory • Ways of working with data • Types of “Models” • File database model • Hierarchical database model • Network database model • Relational database model
Relational Database Theory • The Relational Theory • Meaning of database model • The way data is organized & stored • The way data is manipulated
Relational Database Theory • Relational Model of Data • Published in 1970 by Dr. Edgar (Ted) Codd – IBM • “A Relational Model of Data for Large Shared Data Banks”
Relational Database Theory • Relational Model of Data • Purpose • Achieve program/data structure independence • Treat data in a disciplined way • Apply rigor of mathematics • Uses Set Theory – sets of related data • Improve programmer productivity
Relational Database Theory • The Relational Model • Relational uses familiar concepts • The data is perceived as organized in tables • Relational also incorporates the rigor of mathematics • Rows of the table are treated as elements in a set • Manipulation of rows is based on set operations – (Vinn Diagrams) • User works with a set of rows at a time
Relational Database Theory • Relational also impacts Data Design • Files were often constructed to support an application • Tables are designed to describe one thing or Entity in the database
Relational Database Theory • Example of a Relation: • ANIMAL – Entity (Relation)
Relational Database Theory • Definition of a Relation • Data is organized & stored in structures called relations • A relation is a table that adheres to certain rules • A relation can be called a table
Relational Database Theory • Definition of a Relation • A relation is a table containing all the data about some entity • An entity is a thing or object that is important in this application area • Data items in the table are related
Relational Database Theory • Relational Data Structure Name Species Weight Domains Attributes Primary Key Tuples Relation
Relational Database Theory • Relational Data Structure Definitions • Relation • The Table • Tuple • A Row • Attribute • A Column
Relational Database Theory • Relational Data Structure Definitions • Primary Key • A unique identifier for the table • Domain • A pool of legal values from which an attribute value is selected • Related to meaning • Has a Data Type
Relational Database Theory • Relational Data Structure Definitions • Degree • The number of attributes • Cardinality • The number of tuples
Relational Database Theory • Relational Table Rules • A Relation is a table that adheres to the following rules: • There are No Duplicate Tuples in the table • The tuples in the table are treated as a mathematical set
Relational Database Theory • Relational Table Rules • By definition, a set is a collection of unique elements • There must be a primary key (unique identifier) for each tuple
Relational Database Theory • Relational Table Rules • There is no order to the tuples (top to bottom) • There is no order to the attributes (left to right) • By convention, the primary key attribute is usually the first one on the left side of the table
Relational Database Theory • Attributes • Each attribute has a datatype • Examples: Integer, character, date, user-defined • The data value of an attribute can be null
Relational Database Theory • Attributes • Each attribute value is atomic • There is One & Only One data value in each cell of the table • There are no Lists or Arrays • One fact per field, one field per fact • Can be called a Field (MS Access)
Relational Database Theory • Relational Data Structure: Design • Each relation contains data about only one entity • Each row corresponds to one unique occurrence of the entity • A relation does not contain arrays, lists or repeating groups • No multi-valued attributes
Relational Database Theory • Tables are designed according to Rules of Normalization • Each data item in the table is determined • By the Primary Key • By the Whole Primary Key • Only by the Primary Key
Relational Database Theory • Normalization avoids well-known update problems • Optimizes design to minimize redundancy & storage requirements
Relational Database Theory • Example: Table with repeating group • Animal
Relational Database Theory • Example: Table with no repeating group Animal-Food Animal
Relational Database Theory • A Database Models the Real World • A Database represents Reality • The database is a collection of relations • A relation represents an entity type • Each tuple represents one occurrence of that entity type • Each occurrence of an entity is unique
Relational Database Theory • A Database Models the Real World • A database contains information about • Entities • Relationships between entities • Rules about the entities’ data & the relationships
Relational Database Theory • Relational Databases Support Relationships • Relational databases support relationships between entities • Relationship is established by a Foreign Key • Repeat the Primary Key of one table in the related table(s)
Relational Database Theory • Example: The Zoo has an “Adopt-an-Animal” program • A zoo member can adopt an animal Foreign Key Zoo-Member Animal
Relational Database Theory • Example: Another Relationship Animal-Food Composite Primary Key Animal Foreign Key
Relational Database Theory • Relational Integrity Rules • Entity Integrity • No part of the Primary Key (PK) may be Null • Referential Integrity • The value of a Foreign Key (FK) must either • Be Null or • Be one of the values of the PK in the related table
Relational Database Theory • Keys, Keys, and More Keys • Characteristic of a Primary Key (PK) • Unique • Mandatory • Unchanging • Under the control of IT organization
Relational Database Theory • Keys, Keys, and More Keys • Names or Types of Keys • Candidate Key • A minimal set of attributes that can be used as the unique identifier for a table
Relational Database Theory • Keys, Keys, and More Keys • Names or Types of Keys • Primary Key • One of the candidate keys • Alternate Key • A candidate key that is not the primary key
Relational Database Theory • Keys, Keys, and More Keys • Names or Types of Keys • Foreign Key • A primary key of a related table • Indicates relationships
Relational Database Theory • Keys, Keys, and More Keys • Names or Types of Keys • Composite Key • A key composed of more than one attribute • Search Key • One or more attributes on which a retrieval is based • Indexes
Relational Database Theory • Characteristics of Relationships • Referential integrity applies to the relationship between entities • Also known as an existence constraint or an enterprise rule • For every relationship, referential integrity must be defined
Relational Database Theory • Relationships have Cardinality • One-To-One • One-To-Many • Many-To-Many • Relationships have Optionality • Each entity’s participation is either • Mandatory or • Optional
Relational Database Theory • Cardinality reflects Business Rules • One-To-One Relationship • One animal is cared for by one zoo worker • One zoo worker cares for one animal
Relational Database Theory • Cardinality reflects Business Rules • One-To-Many Relationship • One animal is cared for by many zoo workers • One zoo worker cares for only one animal
Relational Database Theory • Cardinality reflects Business Rules • Many-To-Many Relationship • One animal is cared for by many zoo workers • One zoo worker cares for many animals
Relational Database Theory • Mandatory Relationship • The Foreign Key Cannot be Null • Every purchase order must have a supplier • In the example below the FK, SNO, cannot be Null
Relational Database Theory • Example: PORDER SUPPLIER
Relational Database Theory • Example: FK can be Null Foreign Key ZOO-MEMBER ANIMAL
Relational Database Theory • What happens when a Tuple is deleted? • For every relationship, there are three possible delete options • Cascades • Delete the target tuple and • Delete the related tuples
Relational Database Theory • Restricted • Delete restricted to cases for which there are no related tuples • Nullifies • Delete the target tuple and • Set the FK to null in the related tuples
Relational Database Theory • Relational Algebra Operations • Select • Project • Join • Union • Intersect • Difference
Relational Database Theory • Our Zoo Database Tables ANIMAL-FOOD ANIMAL ZOO-MEMBER
Relational Database Theory • Relational Algebra: SELECT • Extracts specified tuples from a relation (or get rows from a table)
Relational Database Theory • Example: SELECT out from the ANIMAL-FOOD table (display) the rows where FOOD=PEOPLE ANIMAL-FOOD RESULTS
Relational Database Theory • Relational Algebra: PROJECT • Extracts specified attributes(columns) from a relation (or get columns from a table)