The Relational Model Database Systems Lecture 3 Natasha Alechina.

Slides:



Advertisements
Similar presentations
Normalisation to 3NF Database Systems Lecture 11 Natasha Alechina.
Advertisements

The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
Monash University Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Relations The Relational Data Model John Sieg, UMass Lowell.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.
Thomas Connolly and Carolyn Begg’s
Entity/Relationship Modelling
Database Architecture The Relational Database Model.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Database Systems Lecture 5 Natasha Alechina
1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.
Database Systems Lecture # 8 11 th Feb,2011. The Relational Model of Data The term relation is basically just a mathematical term for a table. DBMS products.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Module Title? DBMS E-R Model to Relational Model.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Fundamentals of Relational Database Yong Choi School of Business CSUB, Bakersfield.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
The relational model1 The relational model Mathematical basis for relational databases.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
COP Introduction to Database Structures
Chapter 2: Relational Model
RELATION.
Translation of ER-diagram into Relational Schema
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Transparencies
Database Design: Relational Model
INSTRUCTOR: MRS T.G. ZHOU
Presentation transcript:

The Relational Model Database Systems Lecture 3 Natasha Alechina

The Relational Model In This Lecture Relational data integrity For more information Connolly and Begg chapter 3 E.F. Codd’s paper `A Relational Model of Data for Large Shared Data Banks’ – a link from the module web page, ~nza/G51DBS07.

The Relational Model Introduced in E.F. Codd’s 1970 paper “A Relational Model of Data for Large Shared Databanks” The foundation for most (but not all) current database systems Concerned with 3 main things Data structure (how data is represented) Data integrity (what data is allowed) Data manipulation (what you can do with the data)

The Relational Model Relational Data Structure Data is stored in relations (tables) Each relation has a scheme (heading) The scheme defines the relation’s attributes (columns) Data takes the form of tuples (rows) NameAge John23 Mary20 Mark18 Jane21 Attributes Scheme Tuples

The Relational Model New thing:scheme (and attributes) NameAge John23 Mary20 Mark18 Jane21 Attributes Scheme Tuples 12 John23 Mary20 Mark18 Jane21 Just numbers of columns Tuples Before…After

The Relational Model Unnamed and named tuples NameAge John23 Mary20 Mark18 Jane21 Attributes Scheme Tuples 12 John23 Mary20 Mark18 Jane21 Just numbers of columns Tuples A tuple is {(Name,John), (Age,23)}

The Relational Model Not a big difference! There is no fundamental difference between named and unnamed perspectives on relations We could have written tuples as sets of pairs {(1,a), (2,b),(3,c)}, only we know anyway in which order 1,2,3 go, so we can skip the numbers. Written as sets of pairs (partial functions), tuples can be written in any order, e.g. {(3,c),(2,b),(1,a)}.

The Relational Model Relational Data Structure More formally - A scheme is a set of attributes A tuple assigns a value to each attribute in its scheme A relation is a set of tuples with the same scheme { { (Name, John), (Age, 23) }, { (Name, Mary), (Age, 20) }, { (Name, Mark), (Age, 18) }, { (Name, Jane), (Age, 21) } } NameAge John23 Mary20 Mark18 Jane21

The Relational Model Relations IDNameSalaryDepartment M139John Smith18,000Marketing M140Mary Jones22,000Marketing A368Jane Brown22,000Accounts P222Mark Brown24,000Personnel A367David Jones20,000Accounts Attributes are ID, Name, Salary, and DepartmentDegree is 4 Cardinality is 5 Tuples, e.g. { (ID, A368), (Name, Jane Brown), (Salary, 22,000), (Department, Accounts) } Scheme is {ID, Name, Salary, Department}

The Relational Model Relational Data Integrity Data integrity controls what data can be in a relation Domains restrict the possible values a tuple can assign to each attribute Candidate and Primary Keys identify tuples within a relation Foreign Keys link relations to each other

The Relational Model Attributes and Domains A domain is given for each attribute The domain lists the possible values for that attribute Each tuple assigns a value to each attribute from its domain Examples An ‘age’ might have to come from the set of integers between 0 and 150 A ‘department’ might come from a given list of strings A ‘notes’ field might allow any string at all

The Relational Model Candidate Keys A set of attributes in a relation is called a candidate key if, and only if, Every tuple has a unique value for the set of attributes (uniqueness) No proper subset of the set has the uniqueness property (minimality) IDFirstLast S139JohnSmith S140MaryJones S141JohnBrown S142JaneSmith Candidate key: {ID}; {First,Last} looks plausible but we may get people with the same name {ID, First}, {ID, Last} and {ID, First, Last} satisfy uniqueness, but are not minimal {First} and {Last} do not give a unique identifier for each row

The Relational Model Choosing Candidate Keys Important: don’t look just on the data in the table to determine what is a candidate key The table may contain just one tuple, so anything would do! Use knowledge of the real world – what is going to stay unique!

The Relational Model Primary Keys One Candidate Key is usually chosen to be used to identify tuples in a relation This is called the Primary Key Often a special ID attribute is used as the Primary Key

The Relational Model NULLs and Primary Keys Missing information can be represented using NULLs A NULL indicates a missing or unknown value More on this later... Entity Integrity: Primary Keys cannot contain NULL values

The Relational Model Foreign Keys Foreign Keys are used to link data in two relations. A set of attributes in the first (referencing) relation is a Foreign Key if its value always either Matches a Candidate Key value in the second (referenced) relation, or Is wholly NULL This is called Referential Integrity

The Relational Model Foreign Keys - Example Department DIDDName 13Marketing 14Accounts 15Personnel Employee EIDENameDID 15John Smith13 16Mary Brown14 17Mark Jones13 18Jane SmithNULL {DID} is a Candidate Key for Department - Each entry has a unique value for DID {DID} is a Foreign Key in Employee - each Employee’s DID value is either NULL, or matches an entry in the Department relation. This links each Employee to (at most) one Department

The Relational Model Foreign Keys - Example Employee IDNameManager E1496John SmithE1499 E1497Mary BrownE1498 E1498Mark JonesE1499 E1499Jane SmithNULL {ID} is a Candidate Key for Employee, and {Manager} is a Foreign Key, which refers to the same relation - every tuple’s Manager value is either NULL or matches an ID value

The Relational Model Referential Integrity When relations are updated, referential integrity can be violated This usually occurs when a referenced tuple is updated or deleted There are a number of options: RESTRICT - stop the user from doing it CASCADE - let the changes flow on NULLIFY - make values NULL

The Relational Model Referential Integrity - Example What happens if Marketing’s DID is changed to 16 in Department? The entry for Accounts is deleted from Department? Department DIDDName 13Marketing 14Accounts 15Personnel Employee EIDENameDID 15John Smith13 16Mary Brown14 17Mark Jones13 18Jane SmithNULL

The Relational Model RESTRICT RESTRICT stops any action that violates integrity You cannot update or delete Marketing or Accounts You can change Personnel as it is not referenced Department DIDDName 13Marketing 14Accounts 15Personnel Employee EIDENameDID 15John Smith13 16Mary Brown14 17Mark Jones13 18Jane SmithNULL

The Relational Model CASCADE CASCADE allows the changes made to flow through If Marketing’s DID is changed to 16 in Department, then the DIDs for John Smith and Mark Jones also change If Accounts is deleted then so is Mary Brown Department DIDDName 13Marketing 14Accounts 15Personnel Employee EIDENameDID 15John Smith13 16Mary Brown14 17Mark Jones13 18Jane SmithNULL 16

The Relational Model NULLIFY NULLIFY sets problem values to NULL If Marketing’s DID changes then John Smith’s and Mark Jones’ DIDs are set to NULL If Accounts is deleted, Mary Brown’s DID becomes NULL Department DIDDName 13Marketing 14Accounts 15Personnel Employee EIDENameDID 15John Smith13 16Mary Brown14 17Mark Jones13 18Jane SmithNULL NULL 16 NULL

The Relational Model Naming Conventions Naming conventions A consistent naming convention can help to remind you of the structure Assign each table a unique prefix, so a student name may be stuName, and a module name modName Naming keys Having a unique number as the primary key can be useful If the table prefix is abc, call this abcID A foreign key to this table is then also called abcID

The Relational Model Example Enrolment stuID modID Student stuID stuName Module modID modName These entries are clearly related to the Student table These entries are clearly related to the Module table These entries are clearly related to tables other than Enrolment

The Relational Model Next Lecture Entity/Relationship models Entities and Attributes Relationships and Cardinality Ratios E/R Diagrams For more information Connolly and Begg chapter 11. Ullman and Widom chapter 2.