Download presentation
Presentation is loading. Please wait.
Published byDebra Patrick Modified over 9 years ago
1
The Relational Model J.G. Zheng Jan 2010 CIS 8040 Database Management Systems
2
Overview What is the relational model? What are the most important practical elements of relational model?
3
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
4
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
5
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
6
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
7
Relation Example
8
Non-Relation Examples (1)
9
Non-Relation Examples (2) Emp_NameEmp_AgeEmp_Phone Emp_Email Jordan Hail45404-652-6325678-584-1754 JH@work.com, JH@home.com Jack Parsons28404-652-8745404-321-5687JP@work.com Tom Jackson23678-854-1245770-415-8415 TJ@work.com, TJ@home.com Liz MarstenThirty404-884-8753404-697-2587 RM@work.com, RM@home.com Jordan Hail45404-652-6325678-584-1754 JH@work.com, JH@home.com
10
Are they the same?
11
Terminology Contrast Database industry TableRowColumn File processing FileRecordField Academic RelationTupleAttribute
12
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
13
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
14
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
15
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
16
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)
17
Relationship Example Primary Key (PK) Foreign Key (FK)
18
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 Department Foreign Key Primary Key
19
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
20
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
21
“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
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
23
Summary Key concepts Relation Keys Primary key, candidate key, surrogate key Composite key Foreign key Referential integrity Null
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.