In mathematical terms, the relation itself can be expressed simply in terms of the attributes it contains:

Similar documents
Chapter 4. The Relational Model

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

EE221 Databases Practicals Manual

Lecture 03. Spring 2018 Borough of Manhattan Community College

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Relational Model. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

King Fahd University of Petroleum and Minerals

Relational Model Concepts

Chapter 2 Introduction to Relational Models

CS211 Lecture: Database Design

II. Review/Expansion of Definitions - Ask class for definitions

Database Technologies. Madalina CROITORU IUT Montpellier

CS 377 Database Systems

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

Lecture 03. Fall 2017 Borough of Manhattan Community College

The University of Nottingham

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E)

Relational Database design. Slides By: Shree Jaswal

Chapter 2: Relational Model

Let s briefly review important EER inheritance concepts

Relational Data Model

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Module Contact: Dr Beatriz de la Iglesia, CMP Copyright of the University of East Anglia Version 1

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Database Systems Relational Model. A.R. Hurson 323 CS Building

DBMS. Relational Model. Module Title?

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, Normal Forms. University of Edinburgh - January 30 th, 2017

Chapter 2: Intro to Relational Model

Lecture 11 - Chapter 8 Relational Database Design Part 1

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B.

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 5-1

The Relational Model

begin [atomic] operation, operation, { commit rollback} end

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Databases. Jörg Endrullis. VU University Amsterdam

Chapter 7: Entity-Relationship Model

Chapter 5. Relational Model Concepts 5/2/2008. Chapter Outline. Relational Database Constraints

Chapter 5. Relational Model Concepts 9/4/2012. Chapter Outline. The Relational Data Model and Relational Database Constraints

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

Database Management Systems LECTURE NOTES 2

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

The En'ty Rela'onship Model

The Relational Data Model and Relational Database Constraints

Conceptual Data Models for Database Design

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 10-2

CSE 132A Database Systems Principles

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1

Relational Data Model. Christopher Simpkins

Computer Science Applications to Cultural Heritage. Relational Databases

FUNCTIONAL DEPENDENCIES CHAPTER , 15.5 (6/E) CHAPTER , 10.5 (5/E)

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

CSC 453 Database Technologies. Tanu Malik DePaul University

Informal Design Guidelines for Relational Databases

The strategy for achieving a good design is to decompose a badly designed relation appropriately.

CS221 Lecture: The Relational Data Model

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

CS352 Lecture - The Entity-Relationship Model

Integrity and Security

Logical Database Design. ICT285 Databases: Topic 06

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Relational model. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

Chapter 6: Entity-Relationship Model

ER Modeling ER Diagram ID-Dependent and Weak Entities Pg 1

Functional Dependencies and Normalization for Relational Databases Design & Analysis of Database Systems

Introduction to Database Systems. The Relational Data Model

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

CS425 Midterm Exam Summer C 2012

Relational Model. Courses B0B36DBS, A4B33DS, A7B36DBS: Database Systems. Lecture 02: Martin Svoboda

Introduction to Database Systems. The Relational Data Model. Werner Nutt

MySQL. A practical introduction to database design

CS275 Intro to Databases

Chapter 14 Outline. Normalization for Relational Databases: Outline. Chapter 14: Basics of Functional Dependencies and

UNIT 3 DATABASE DESIGN

Database Management Systems

01/01/2017. Chapter 5: The Relational Data Model and Relational Database Constraints: Outline. Chapter 5: Relational Database Constraints

Chapter 7: Entity-Relationship Model

Chapter 10. Chapter Outline. Chapter Outline. Functional Dependencies and Normalization for Relational Databases

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

IGCSE Information Communication Technology (ICT) Syllabus code Section 5: Data types

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

Database Design Theory and Normalization. CS 377: Database Systems

CSIT5300: Advanced Database Systems

Chapter 14. Database Design Theory: Introduction to Normalization Using Functional and Multivalued Dependencies

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

DC62 Database management system JUNE 2013

A hypothetical M:M student schedule example

Information Services. Essential Access Exercises. IT

Relational Algebra for sets Introduction to relational algebra for bags

Running Example Tables name location

The data structures of the relational model Attributes and domains Relation schemas and database schemas

Transcription:

The Relational Model The relational data model organises data as 2-dimensional tables or relations. An example of one such relation would be STUDENT shown below. As we have seen in the wine list example, tables (relations) hold information in rows that can be updated, added to or deleted. RELATION: STUDENT ID Surname Sex Birth_Place Date_of_Birth P1 Smith Male Dublin 030382 P2 Jones Female Galway 040281 P3 Malone Male Mayo 020381 Terminology In everyday terms, the table STUDENT contains five columns and three rows (or entries). However, in relational theory, the terminology has been formalised and is based on the relation s mathematical structure. Therefore, the rows of a relation are known as tuples while the columns are the attributes of the relation. Each tuple of a relation holds individual pieces of information for each of the attributes specified. For example, the value of the Surname attribute in the first tuple is Smith. In mathematical terms, the relation itself can be expressed simply in terms of the attributes it contains: STUDENT (ID, Surname, Sex, Birth_Place, Date_of_Birth) We call a relation with specific sample data, for example the table above, an instance of the relation. Note that different terminology can be used in books for attributes, tuples and relations (as table below). We will use the mathematical terminology in these notes. Mathematical terminology In database manuals In some books Relation Table Table Attribute Field Column Tuple Record Row Database Systems (EE221) - Page 10

A database can be made up of more than one relation. In order to be able to locate information in the database, each relation must have a unique name (to differentiate between relations); as must each attribute of a relation (no two attributes may have the same name within one relation but there is no restriction on having the same attribute name in two different relations). Domains Let us now consider the characteristics of an attribute s values. Such values come from domains, and the domain for an attribute defines the valid values of that attribute. Domains are a more abstract concept than types or sorts in programming languages - two sets of values can be of the same type but of a different domain. For example, in the STUDENT relation, Surname and Birth_Place are both character strings, but they come from different domains, because they signify different things - Surname is from the domain of all valid surnames, while Birth_Place comes from the domain of all valid locations. Note that, it is permitted for multiple attributes within a relation to hold values from the same domain. For example, if we wished to add an attribute to STUDENT with the name of the next-of-kin, this attribute could also come from the NAME domain. It is also possible for attribute values themselves to be relations, in which case, the attribute domains are instances of that relation. In the relation LIVED-IN, the attribute Residence is in itself, a relation. The attributes of Residence are City and Date-Moved-In. The domain of the attribute Residence is a combination of the domains of its attributes. However, we will see later that using such multi-valued attributes is considered bad practice, and in fact disallowed in most relational theories. RELATION: LIVED-IN Person Residence Martha City Date-Moved-In New York 030303 Boston 070705 Jack City Date-Moved-In Boston 040593 Philadelphia 070699 Database Systems (EE221) - Page 11

Summary of Properties of Relational Tables Relational tables have the following properties: 1. Different relations (tables) must have unique names 2. Each tuple (row) in a relation is unique 3. Each attribute (column) in a relation must have a unique name 4. The order of attributes in a relation is not significant 5. The order of tuples in a relational table is not significant 6. All values of an attribute are from the same domain 7. Values of attributes are atomic (for most relational theories) Keys of Relations The notion of a key is fundamental to relational theory. A key of a relation is a set of one or more attributes that uniquely identify tuples in the relation. That is, given any possible value of the key, at most there will be one tuple in the relation with a matching value of the key attributes. This property is called the uniqueness property of relation keys. For example, in the STUDENT relation, ID is a key to the relation. STUDENT (ID, Surname, Sex, Birth_Place, Date_of_Birth) Note that a relation can (and normally does) have more than one key. Some more terminology A key, as we have defined it above, is normally termed a superkey defined as: a set of attributes whose values identify a unique tuple in a relation. A superkey can include any subset of the relation s attributes that possesses this uniqueness property. For example, in the relation STUDENT, the ID attribute is a superkey, as it uniquely defines a tuple of the relation. Taken together, the attributes ID and SURNAME is also a superkey, because again only one tuple in the relation can have a given value of these attributes. In fact, all the attributes of a relation taken together also form a superkey! This is implied by property 2 above. Note also that a key can never have a null (blank) value. Database Systems (EE221) - Page 12

Relational theory also calls for a more restricted type of key where the number of attributes in a superkey to a minimum (excludes any unnecessary ones). Such keys are called relation keys. A relation key may be formally defined as a set of one or more attributes of a relation such that the following two properties hold for all time for any instance of the relation: Uniqueness: the set of attributes has a unique value for each tuple in the relation. Nonredundancy: if an attribute is removed from the set of attributes in the relation key, then the remaining attributes will not possess the uniqueness property. A relation may also have more than one relation key. If a relation has more than one, it is a good idea to choose one relation key to be the primary key of the relation. This is the key which will be principally used to retrieve a particular tuple (row) from a relation. Note that whether or not a set of attributes forms a relation key is a matter of interpretation for the database designer when creating a data model. Consider the following relation: LECTURER (ID, Name, Telephone_Number, Office_Number) All DCU employees have a unique ID number and these numbers are never reused or changed so the attribute ID will form a relation key. It is possible that two lecturers share an office or telephone, and that lectures can move rooms or phone numbers, so neither of these attributes will form a relation key. However, in an institute where every lecturer always has their own office then Office_Number will also be a relation key. It requires analysis of the particular application to determine these facts and to ensure the database schema correctly mirrors the real world being modelled. Analysis and data modelling is an important part of database design which will be touched on in the next section. Database Systems (EE221) - Page 13

Foreign Keys Another important concept in relational theory is that of a foreign key. A foreign key in the relation R2 is a set of one or more attributes of R2 (not necessarily a part of a relation key of R2) which form a relation key in another relation R1. The foreign key in R2 must come from the same domain as the relation key in R1. As an example, suppose we have two relations in a database used to keep track of which student has been assigned which final year project: STUDENT PROJECT (ID, Surname, Forename, Programme, Date_of_Birth) (Proj-ID, Project-Title, Student-ID, Year) STUDENT just has one relation key, {ID}. Each year the project numbers are reused but the database will store project information over many years, so the relation key of PROJECT is: {Proj-ID, Year} In our example, the attribute Student-ID of PROJECT is designated a foreign key, as it reflects the attribute ID which is the relation key of STUDENT. This example illustrates that the foreign key does not necessarily have to have the same name as the primary key it reflects; however, they must both have the same domain. Foreign keys are important concepts which model the relationships between different entities. For example the existence of the foreign key Student-ID indicates that there is a relationship between the entities STUDENT and PROJECT, that is, each project is assigned to a student. This relationship allows us to navigate between tables when retrieving data and helps to enforce integrity rules in a database. We will see in the next section that these relationships between entities can be expressed graphically using Entity-Relationship (E-R) diagrams. Foreign key ownership Note that it is considered that a foreign key in a relation R1 is owned by the relation who s relation key it reflects. For example, because Student-ID in PROJECT is a foreign key it may only take on an existing value of ID in STUDENT. Otherwise we could loose referential integrity e.g. we could assign a project to a non-existent student (bad). This is why the term foreign is used the attribute or attributes in the foreign key are really just visiting from another relation the value of the foreign key is determined by their home relation. Database Systems (EE221) - Page 14

Prime and Non-Prime Attributes The final piece of terminology to be introduced refers to prime and nonprime attributes. A prime attribute is an attribute which is part of at least one relation key. A non-prime attribute is an attribute that is not part of any relation key. Examples of prime attributes in PROJECT are Proj-ID and Year, while nonprime attributes are Project-Title and Student-ID. Database Integrity Rules There are two rules relating to database integrity which must be obeyed at all times to ensure that data can be maintained and retrieved successfully. To understand their significance, imagine what would happen if one of the attributes of a primary key were left blank when a tuple was inserted into a relation it would be impossible to ever retrieve that tuple. Similarly, a problem will exist if a foreign key of a relation contains a value which is not reflected in the relation where this attribute is a primary key. For example, if a particular Student-ID in the PROJECT relation did not have a corresponding value of ID in the STUDENT relation, then there would be confusion in the logic of the database, i.e. the project would be assigned to a non-existent student. The two database integrity rules are: 1. Entity Integrity: No attribute participating in the primary key of a relation is allowed to accept null values. The primary key is the unique identifier in a relation - lack of information in the primary key would result in tuples which have no identity. This cannot be permitted. 2. Referential Integrity: If a relation R2 contains a foreign key (i.e. one or more attributes which form a primary key in another relation R1), then every value of the foreign key must either correspond to values in R1, or be wholly null. This ensures that if some tuple t2 references another tuple tl, then tl must exist, therefore ensuring no conflicting information in the data. Database Systems (EE221) - Page 15

Exercise 1 Given the group of four relations and the additional information listed below: (1) Identify all relation keys for each relation. (2) Identify a suitable primary key for each relation. (3) Identify any foreign keys in the set of relations. (4) Identify the non-prime attributes in each relation. In each case, state any assumptions you make about your interpretation of the relationships between the attributes. STUDENT (Student_ID, First_Name, Last_Name, Address, E-mail) REGISTER (Student_ID, Module_ID, Semester) LECTURER (Lecturer_ID, First_Name, Last_Name, E-mail, Office_Number) MODULE (Module_ID, Module_Name, Faculty, Lecturer_ID) The following information is also known: Each student and lecturer has their own unique e-mail address. More than one student may live at the same address. A student may register for a module more than once (e.g. to repeat it), but only once in any given semester. (Note: the values of Semester include a year code e.g. 2-07 is Semester 2 in 2007, etc.). Lecturers may share an office but, if they do, they will not have the same last name. Two faculties may happen to use the same module name for two distinct modules. Exercise 2 In each of the following groups of relations, identify the relation keys, stating any assumptions. Are there any likely foreign keys? Qualify your answer. List the prime and the non-prime attributes in each relation. (i) RESIDENCE (House-Number, Street-Name, City, Country, Date-moved-in) LIVED-IN (Person-ID, Residence-ID) (ii) CITIES (Map-Reference, City-Name, Population) ROADS (Road-Name, Start-City-Name, End-City-Name) Database Systems (EE221) - Page 16