Lecture 03. Fall 2017 Borough of Manhattan Community College

Similar documents
Lecture 03. Spring 2018 Borough of Manhattan Community College

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

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

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

Chapter 6. SQL: SubQueries

Chapter 3. The Relational database design

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


Lecture 07. Spring 2018 Borough of Manhattan Community College

CS317 File and Database Systems

Database Technologies. Madalina CROITORU IUT Montpellier

RELATIONAL DATA MODEL

Transforming ER to Relational Schema

Entity Relationship Modeling

Conceptual Database Design

Database Technologies. Madalina CROITORU IUT Montpellier

CS317 File and Database Systems

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

CS317 File and Database Systems

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

Lecture 09. Spring 2018 Borough of Manhattan Community College

Theory 2 Hours/Week 2 credits

STRUCTURED QUERY LANGUAGE (SQL)

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

DB Creation with SQL DDL

3ISY402 DATABASE SYSTEMS

Physical Database Design

Relational Data Model

Database Technologies. Madalina CROITORU IUT Montpellier

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

Lecture 01. Fall 2018 Borough of Manhattan Community College

The Entity Relationship Model

Chapter 2 Introduction to Relational Models

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

Review for Exam 1 CS474 (Norton)

COMP102: Introduction to Databases, 9.1

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

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

CMP-3440 Database Systems

Chapter 6. SQL Data Manipulation

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

DATABASE MANAGEMENT SYSTEMS. UNIT I Introduction to Database Systems

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

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

Relational Model. CS 377: Database Systems

DBMS Chapter Three IS304. Database Normalization-Comp.

File Processing Approaches

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

DATABASE TECHNOLOGY - 1DL124

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

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

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

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

Lecture 5 Data Definition Language (DDL)

DATABASE DESIGN I - 1DL300

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

CS317 File and Database Systems

Database Management System 9

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

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

Chapter 5. Relational Algebra and Relational Calculus

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

Relational Database Systems Part 01. Karine Reis Ferreira

Chapter 12. Entity-Relationship Modeling

Introduction to Database Systems. The Relational Data Model

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

Relational Algebra and Relational Calculus. Pearson Education Limited 1995,

PART III SOLUTIONS TO REVIEW QUESTIONS AND EXERCISES

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

Lecture 02. Fall 2017 Borough of Manhattan Community College

Lecture 05. Spring 2018 Borough of Manhattan Community College

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

Chapter 17. Methodology Logical Database Design for the Relational Model

Data Models. CS552- Chapter Three

The Relational Model

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

Standard Query Language. SQL: Data Definition Transparencies

Handout 4. Logical Database Modeling, Part 1: Relational Data Model. Transforming EER model to Relational.

Lecture 6 Structured Query Language (SQL)

THE RELATIONAL DATABASE MODEL

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

Normalization. { Ronak Panchal }

CS 377 Database Systems

SQL DDL. Intro SQL CREATE TABLE ALTER TABLE Data types Service-based database in Visual Studio Database in PHPMyAdmin

Chapter 2 Conceptual Modeling. Objectives

CS317 File and Database Systems

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

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

Database Applications (15-415)

The Relational Model

Running Example Tables name location

Lecture 10. Spring 2018 Borough of Manhattan Community College

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

Solved MCQ on fundamental of DBMS. Set-1

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

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

Conceptual Data Models for Database Design

Transcription:

Lecture 03 Fall 2017 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 2.1 Relational Data Structure 2.2 Mathematical Relations 2.3 Database Relations 2.4 Properties of Relations 2.5 Relational Keys 2.6 Representing Relational Database Schemas 3 Integrity Constraints 4 Views 6

Terminology 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. In this section we explain the terminology and structural concepts of the relational model: Relational Data Structure Mathematical Relations Database Relations Properties of Relations Relational Keys Representing Relational Database Schemas 7

Relational Data Structure A relation is a table with columns and rows. Note that this perception applies only to the logical structure of the database: that is, the external and conceptual levels of the ANSI-SPARC architecture. It does not apply to the physical structure of the database, which can be implemented using a variety of storage structures. 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. 8

Relational Data Structure 9

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. 10

Relational Data Structure 11

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 (or state) of a relation, which changes over time. 12

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. 13

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. 14

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

Mathematical Relations 16

Mathematical Relations 17

Mathematical Relations 18

Database Relations 19

Database Relations 20

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. 21

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. 22

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. 23

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. 24

25

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 144 Fifth Av 3F New York 10006 Apartment $3,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: Address, Apt#, City Address, Apt#, Zip PropID Primary key: PropID Alternate keys: Address, Apt#, City Address, Apt#, Zip 26

27

28

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. 29

Homework - 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) Booking (guestno, hotelno, roomno, datefrom, dateto) Identify: Foreign keys Candidate keys Primary keys Alternate keys 30

Outline 1 Brief History of the Relational Model 2 Terminology 3 Integrity Constraints 3.1 Nulls 3.2 Entity Integrity 3.3 Referential Integrity 3.4 General Constraints 4 Views 31

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. 32

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. 33