Lecture 03. Spring 2018 Borough of Manhattan Community College

Similar documents
Lecture 03. Fall 2017 Borough of Manhattan Community College

Database Systems. A Practical Approach to Design, Implementation, and Management. Database Systems. Thomas Connolly Carolyn Begg

Chapter 4. The Relational Model

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

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

Objective. The goal is to review material covered in Chapters 1-5. Do the following questions from the book.

Chapter 6. SQL: SubQueries

Chapter 3. The Relational database design

Relational Data Model ( 관계형데이터모델 )


Lecture 07. Spring 2018 Borough of Manhattan Community College

RELATIONAL DATA MODEL

CS317 File and Database Systems

Database Technologies. Madalina CROITORU IUT Montpellier

Transforming ER to Relational Schema

Conceptual Database Design

CS317 File and Database Systems

Entity Relationship Modeling

3ISY402 DATABASE SYSTEMS

CS317 File and Database Systems

Database Technologies. Madalina CROITORU IUT Montpellier

STRUCTURED QUERY LANGUAGE (SQL)

Lecture4: Guidelines for good relational design Mapping ERD to Relation. Ref. Chapter3

Lecture 09. Spring 2018 Borough of Manhattan Community College

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Data Model

Lecture 01. Fall 2018 Borough of Manhattan Community College

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

Example 1 - Create Horizontal View. Example 2 - Create Vertical View. Views. Views

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

Physical Database Design

Chapter 2 Introduction to Relational Models

Database Management System 9

CMP-3440 Database Systems

Theory 2 Hours/Week 2 credits

DB Creation with SQL DDL

Database Technologies. Madalina CROITORU IUT Montpellier

Review for Exam 1 CS474 (Norton)

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

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

ER Model. Objectives (2/2) Electricite Du Laos (EDL) Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 1

DATABASE MANAGEMENT SYSTEMS. UNIT I Introduction to Database Systems

SOLUTIONS TO REVIEW QUESTIONS AND EXERCISES FOR PART 3 - DATABASE ANALYSIS AND DESIGN (CHAPTERS 10 15)

OBJECTIVES. How to derive a set of relations from a conceptual data model. How to validate these relations using the technique of normalization.

The Entity Relationship Model

Chapter 6. SQL Data Manipulation

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

Lecture 5 Data Definition Language (DDL)

DATABASE DESIGN I - 1DL300

Lecture 05. Spring 2018 Borough of Manhattan Community College

1 P a g e D a t a b a s e o l d p a p e r b y w a s i m

COMP102: Introduction to Databases, 9.1

Chapter 5. Relational Algebra and Relational Calculus

Standard Query Language. SQL: Data Definition Transparencies

DATABASE TECHNOLOGY - 1DL124

Relational Algebra and Relational Calculus. Pearson Education Limited 1995,

The Relational Model

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

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

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

Relational Model. CS 377: Database Systems

CS317 File and Database Systems

Data Models. CS552- Chapter Three

DBMS Chapter Three IS304. Database Normalization-Comp.

CISC 3140 (CIS 20.2) Design & Implementation of Software Application II

Lecture 6 Structured Query Language (SQL)

Using High-Level Conceptual Data Models for Database Design A Sample Database Application Entity Types, Entity Sets, Attributes, and Keys

Relational Database Systems Part 01. Karine Reis Ferreira

8) A top-to-bottom relationship among the items in a database is established by a

THE RELATIONAL DATABASE MODEL

File Processing Approaches

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Chapter 17. Methodology Logical Database Design for the Relational Model

PART III SOLUTIONS TO REVIEW QUESTIONS AND EXERCISES

Data about data is database Select correct option: True False Partially True None of the Above

Databases 1. Daniel POP

Data Modeling with the Entity Relationship Model. CS157A Chris Pollett Sept. 7, 2005.

Database Applications (15-415)

Relational Database Model. III. Introduction to the Relational Database Model. Relational Database Model. Relational Terminology.

LECTURE 6: GUIDELINES FOR GOOD RELATIONAL DESIGN MAPPING ERD TO RELATIONS

CS317 File and Database Systems

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

6.9 List the names and addresses of all guests in London, alphabetically ordered by name.

CMP-3440 Database Systems

Basant Group of Institution

Mahathma Gandhi University

Database Technology Introduction. Heiko Paulheim

RELATIONAL DATA MODEL

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

Running Example Tables name location

CS 377 Database Systems

Introduction to Database Systems. The Relational Data Model

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


Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science

Chapter 14. Chapter 14 - Objectives. Purpose of Normalization. Purpose of Normalization

Chapter 12. Entity-Relationship Modeling

Database Systems. A Practical Approach to Design, Implementation, and Management. Database Systems. Thomas Connolly Carolyn Begg

Lecture 02. Fall 2017 Borough of Manhattan Community College

Transcription:

Lecture 03 Spring 2018 Borough of Manhattan Community College 1

2

Outline 1. Brief History of the Relational Model 2. Terminology 3. Integrity Constraints 4. Views 3

History of the Relational Model The Relational Database Management System (RDBMS) has become the dominant data-processing software in use today. This software represents the second generation of DBMSs and is based on the relational data model proposed by E. F. Codd in 1970. Commercial systems based on the relational model started to appear in the late 1970s and early 1980s. Now there are several hundred RDBMSs for both mainframe and PC environments. Owing to the popularity of the relational model, many nonrelational systems now provide a relational user interface, irrespective of the underlying model. 4

History of the Relational Model The relational model s objectives were specified as follows: To allow a high degree of data independence. Application programs must not be affected by modifications to the internal data representation, particularly by changes to file organizations, record orderings, or access paths. To provide substantial grounds for dealing with data semantics, consistency, and redundancy problems. In particular, Codd introduced the concept of normalized relations, that is, relations that have no repeating groups. To enable the expansion of set-oriented data manipulation languages. 5

Outline 1. Brief History of the Relational Model 2. Terminology 1. Relational Data Structure 2. Mathematical Relations 3. Database Relations 4. Properties of Relations 5. Relational Keys 6. Representing Relational Database Schemas 3. 3 Integrity Constraints 4. 4 Views 6

Relational Data Structure The relational model is based on the mathematical concept of a relation, which is physically represented as a table. Codd, a trained mathematician, used terminology taken from mathematics, principally set theory and predicate logic. A relation is a table with columns and rows. An attribute is a named column of a relation. A relation is represented as a two-dimensional table in which the rows of the table correspond to individual records and the table columns correspond to attributes. Attributes can appear in any order and the relation will still be the same relation, and therefore will convey the same meaning. 7

Relational Data Structure 8

Relational Data Structure A domain is the set of allowable values for one or more attributes. Every attribute in a relation is defined on a domain. Domains may be distinct for each attribute, or two or more attributes may be defined on the same domain. Note that at any given time there will be values in a domain that do not currently appear as values in the corresponding attribute. The domain concept allows to avoid operations that are semantically incorrect. For example, it is not sensible to compare a street name with a telephone number. 9

Relational Data Structure 10

Relational Data Structure A tuple is a row of a relation. The elements of a relation are the rows or tuples in the table. Tuples can appear in any order and the relation will still be the same and therefore convey the same meaning. The structure of a relation, together with a specification of the domains and any other restrictions on possible values, is sometimes called its intension, which is usually fixed, unless the meaning of a relation is changed to include additional attributes. The tuples are called the extension of a relation, which changes over time. 11

Relational Data Structure The degree of a relation is the number of attributes it contains. A relation of degree n means that each row of the table is an n-tuple, containing n values. A relation with only one attribute would have degree one and be called a unary relation or one-tuple. A relation with two attributes is called binary. A relation with three attributes is called ternary, and after that the term n-ary is usually used. The degree of a relation is a property of the intension of the relation. 12

Relational Data Structure The cardinality of a relation is the number of tuples it contains. The cardinality is a property of the extension of the relation. 13

Relational Data Structure A relational database is a collection of normalized (appropriately structured) relations with distinct relation names. Alternative terminology: 14

Mathematical Relations 15

Mathematical Relations 16

Mathematical Relations 17

Database Relations 18

Database Relations 19

Properties of Relations A relation has the following properties: the relation has a name that is distinct from all other relation names in the relational schema; each cell of the relation contains exactly one atomic (single) value; each attribute has a distinct name; the values of an attribute are all from the same domain; each tuple is distinct; there are no duplicate tuples; the order of attributes has no significance; the order of tuples has no significance. 20

Relational Keys Relational keys are attributes that uniquely identify each tuple in a relation. A superkey is an attribute, or set of attributes, that uniquely identifies each tuple within a relation. However, a superkey may contain additional attributes that are not necessary for unique identification. When a key consists of more than one attribute, we call it a composite key. 21

Relational Keys A candidate key is a superkey such that no proper subset is a superkey within the relation. Therefore, a candidate key K for a relation R has two properties: Uniqueness. In each tuple of R, the values of K uniquely identify that tuple. Irreducibility. No proper subset of K has the uniqueness property. There may be several candidate keys for a relation. Note that an instance of a relation cannot be used to prove that an attribute or combination of attributes is a candidate key. However, the presence of duplicates in an instance can be used to show that some attribute combination is not a candidate key. 22

Relational Keys Identifying a candidate key requires that we know the real-world meaning of the attribute(s) involved so that we can decide whether duplicates are possible. A primary key is the candidate key that is selected to identify tuples uniquely within the relation. The candidate keys that are not selected to be the primary key are called alternate keys. A foreign key is an attribute, or set of attributes, within one relation that matches the candidate key of some relation. When an attribute appears in more than one relation, its appearance usually represents a relationship between tuples of the two relations. 23

24

PropID Address Apt# City Zip Type Price OwnerID P01 250 Broadway 1A Bronx 10718 Apartment $1,800 O79 P02 125 Hudson St 7C New York 10013 Apartment $2,000 O61 P03 8806 Third Av Bay Ridge 11209 House $2,500 O14 P04 250 Broadway 1A Jersey City 07306 Apartment $1,900 O61 P05 125 Hudson St 3F New York 10013 Apartment $1,700 O53 Foreign key: OwnerID Candidate keys: PropID Address, Apt#, City Address, Apt#, Zip Primary key: PropID Alternate keys: Address, Apt#, City Address, Apt#, Zip 25

26

27

Representing Relational DB Schemas A relational database consists of any number of normalized relations. The relational schema for part of the DreamHome case study is: Branch (branchno, street, city, postcode) Staff (staffno, fname, IName, position, sex, DOB, salary, branchno) PropertyForRent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) Client (clientno, fname, IName, telno, preftype, maxrent, email) PrivateOwner (ownerno, fname, IName, address, telno, email, password) Viewing (clientno, propertyno, viewdate, comment) Registration (clientno, branchno, staffno, datejoined) The conceptual model, or conceptual schema, is the set of all such schemas for the database. 28

Relational Keys The following tables form part of a database held in a relational DBMS: Hotel (hotelno, hotelname, city) Room (roomno, hotelno, type, price) Guest (guestno, guestname, guestaddress, guestemail) Booking (guestno, hotelno, roomno, datefrom, dateto) Assumption: A hotel name cannot be repeated in the same city. Identify, for each table, the followings: Foreign keys Candidate keys Primary key Alternate keys 29

Outline 1. Brief History of the Relational Model 2. Terminology 1. Relational Data Structure 2. Mathematical Relations 3. Database Relations 4. Properties of Relations 5. Relational Keys 6. Representing Relational Database Schemas 3. Integrity Constraints 1. Nulls 2. Entity Integrity 3. Referential Integrity 4. General Constraints 4. Views 30

Integrity Constraints A data model has three parts: structural part, discussed in the previous section, a manipulative part, defining the types of operation that are allowed on the data, and a set of integrity constraints, which ensure that the data is accurate. Domain constraints are an example of integrity constraints. They are restrictions on the set of values allowed for the attributes of relations. In addition, there are two important integrity rules, namely the entity integrity and the referential integrity which are constraints or restrictions that apply to all instances of the database. Null represents a value for an attribute that is currently unknown or is not applicable for this tuple. Null is not a value but represents the absence of a value. 31

Integrity Constraints Entity integrity: In a base relation, no attribute of a primary key can be null. If we allow a null for any part of a primary key, we are implying that not all the attributes are needed to distinguish between tuples, which contradicts the definition of the primary key. Referential integrity: If a foreign key exists in a relation, either the foreign key value must match a candidate key value of some tuple in its home relation or the foreign key value must be wholly null. General constraints: Additional rules specified by the users or database administrators of a database that define or constrain some aspect of the enterprise. 32

Outline 1. Brief History of the Relational Model 2. Terminology 3. Integrity Constraints 4. Views 1. Terminology 2. Purpose of Views 3. Updating Views 33

Views A base relation is a named relation corresponding to an entity in the conceptual schema, whose tuples are physically stored in the database. A view is the dynamic result of one or more relational operations operating on the base relations to produce another relation. A view is a virtual relation that does not exist in the database but can be produced upon request by a particular user, at the time of request. Views are dynamic, meaning that changes made to the base relations that affect the view are immediately reflected in the view. When users make permitted changes to the views, these changes are made to the underlying relations. 34

Purpose of Views A view should be designed to support the external model that the user finds familiar. For example: A user might need Branch tuples that contain the names of managers as well as the other attributes already in Branch. This view is created by combining the Branch relation with a restricted form of the Staff relation where the staff position is Manager. Some members of staff should see Staff tuples without the salary attribute. Attributes may be renamed or the order of attributes changed. Some members of staff should see property records only for those properties that they manage. 35

Purpose of Views The view mechanism is desirable for several reasons: It provides a powerful and flexible security mechanism by hiding parts of the database from certain users. Users are not aware of the existence of any attributes or tuples that are missing from the view. It permits users to access data in a way that is customized to their needs, so that the same data can be seen by different users in different ways, at the same time. It can simplify complex operations on the base relations. For example, if a view is defined as a combination (join) of two relations, users may now perform more simple operations on the view, which will be translated by the DBMS into equivalent operations on the join. 36

Updating Views All updates to a base relation should be immediately reflected in all views that reference that base relation. Similarly, if a view is updated, then the underlying base relation should reflect the change. However, there are restrictions on the types of modification that can be made through views. 37

Updating Views Updates are allowed through a view defined using a simple query involving a single base relation and containing either the primary key or a candidate key of the base relation. Updates are not allowed through views involving multiple base relations. Updates are not allowed through views involving aggregation or grouping operations. 38