The Relational Model J.G. Zheng Jan 2010 CIS 8040 Database Management Systems.
-
Upload
debra-patrick -
Category
Documents
-
view
212 -
download
0
Transcript of The Relational Model J.G. Zheng Jan 2010 CIS 8040 Database Management Systems.
The Relational Model
J.G. ZhengJan 2010
CIS 8040Database Management Systems
Overview
What is the relational model?
What are the most important practical elements of relational model?
Introduction
Edgar F. Codd (IBM), 1970
One sentence to summarize relational database model (extremely brief):
Data are organized in relations (tables),which are linked (relationship) by keys
Introduction
What’s in a database? Tables Relationships Metadata
How are data organized in a database? Data are organized in tables, which
are linked (relationship) by keys
Relation
A relation is a two-dimensional table that has specific characteristics: The table consist of rows and columns Rows contain data about entity instances All values in a row describes the same entity
instance Columns contain data about attributes of
the entity All values in a column are of the same kind
Relation (continued)
Relation’s specific characteristics go on: Each row is distinct A Cell of the table hold a single value Each column has a unique name The order of the rows is unimportant The order of the columns is
unimportant
Relation Example
Non-Relation Examples (1)
Non-Relation Examples (2)
Emp_Name Emp_Age Emp_PhoneEmp_Phone Emp_Email
Jordan Hail 45404-652-6325
678-584-1754
[email protected], [email protected]
Jack Parsons 28404-652-8745
404-321-5687 [email protected]
Tom Jackson 23678-854-1245
770-415-8415
[email protected], [email protected]
Liz Marsten Thirty404-884-8753
404-697-2587
[email protected], [email protected]
Jordan Hail 45404-652-6325
678-584-1754
Are they the same?
Terminology Contrast
Database industry Table Row Column
File processing File Record Field
Academic Relation Tuple Attribute
Keys
A key is one or more columns of a relation that is used to identify a record Unique keys
Candidate key Primary key Surrogate key
Foreign key Composite key
Candidate Key/Primary Key
Candidate key The minimum set of column(s) that uniquely
identifies a single record (row)
Primary key Is one of the candidate keys chosen to be the
identifying key There is only one primary key for a relation/table
Primary Key
Primary key is a column/attribute that is used to uniquely identify a record The value of this key column uniquely identifies
a single record (row) There is only one primary key for a table
Can the following attribute uniquely indentify a record? Last Name Student Number Social Security Number ISBN
Artificial Primary Key/Surrogate Key
Very often it is difficult to have a natural attribute to identify one thing
A column is created arbitrarily and assign each record a unique number/id Product Number, Product Id Movie Id Actor Id
Relationship and Foreign Key
Relationship defines how tables (relations) are linked
Two tables are linked by a pair of keys The primary key of one table The foreign key in the linked table These two keys are of the same kind
(may be of different name)
Relationship Example
Primary Key (PK)
Primary Key (PK) Foreign Key (FK)
Foreign Key Example
Primary Key and Foreign Key are of the same type (string, number, etc.) and length, but they do not necessarily have
the same name.
Department
DeptID
DeptName
Location
Employee
EmpID
EmpName
DepartmentForeign Key
Primary Key
Composite Key
Composite key: A key that contains two or more attributes (columns)
Example: “FirstName” + “LastName” “FirstName” + “LastName” + “BirthDate” “FirstName” + “LastName” + “BirthDate” + “BirthCity” …
All keys can be composite keys
True or False: The combination of all columns of a relation is a candidate
key
Referential Integrity
Every value of a foreign key must match a value of the primary key or be “null”
For example (slide #17) In “Customer” table, “RepNum” is a foreign
key (linked to the “Rep” table where “RepNum” is the primary key).
Then every value of “RepNum” in the “Customer” table must exist in the “Rep” table
“Null” Value
“Null” means value is inapplicable: e.g., Fax_Number = Null value is unknown: e.g., Stud_Grade = Null
“Null” does not mean zero blank space
No primary key (or part of a composite primary key) can be null
22
Common Data Types
Numeric INTEGER, SMALLINT DECIMAL(i,j), NUMBER(i,j)
Character/String CHAR(n), VARCHAR(n), Text
Date DATE, DATETIME
Data types reference Access 2007: http://msdn.microsoft.com/en-us/library/bb208866.aspx SQL Server 2005: http://msdn.microsoft.com/en-us/library/ms187752.aspx
Summary
Key concepts Relation Keys
Primary key, candidate key, surrogate key Composite key Foreign key
Referential integrity Null