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

Similar documents
CS5300 Database Systems

Supplier-Parts-DB SNUM SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens

Chapter 4. The Relational Model

Information Systems. Relational Databases. Nikolaj Popov

Relational Data Model

A Sample Solution to the Midterm Test

Unit 3 The Relational Model

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

CS5300 Database Systems

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

The Relational Model and Normalization

CS275 Intro to Databases

Introduction The SELECT statement: basics Nested queries Set operators Update commands Table management

King Fahd University of Petroleum and Minerals

Database Redesign. 1. Additional SQL Statements 3 1) Correlated Sub-Query 3 2) EXISTS 4 3) NOT EXISTS 7 4) double NOT EXISTS (FOR ALL) 9.

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

Chapter 8 INTEGRITY 1

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

Lecture 15: Database Normalization

UFCEKG 20 2 : Data, Schemas and Applications

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

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

MySQL Introduction. Practical Course Integrative Bioinformatics. March 7, 2012

CS 377 Database Systems

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

RELATIONAL DATA MODEL

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

The Relational Data Model and Relational Database Constraints

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

CS2300: File Structures and Introduction to Database Systems

Relational Database Systems Part 01. Karine Reis Ferreira

The Relational Model. Chapter 3

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

The Relational Model. Week 2

Chapter 3. The Relational database design

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

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

Chapter 2: Intro to Relational Model

RELATIONAL DATA MODEL

Introduction to Database Management Systems

CSE 132A Database Systems Principles

The Relational Model

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

The Relational Model

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

Relational data model

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

Chapter 1: Introduction

The Relational Data Model. Data Model

DATABASE MANAGEMENT SYSTEMS

Database Applications (15-415)

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

The Relational Data Model (ALL the Vocabulary)

Relational Design: Characteristics of Well-designed DB

U1. Data Base Management System (DBMS) Unit -1. MCA 203, Data Base Management System

Relational Model Concepts

ECE 650 Systems Programming & Engineering. Spring 2018

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

Database Management

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

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

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

Conceptual Design. The Entity-Relationship (ER) Model

The Relational Model of Data (ii)

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

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

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

Chapter 2: Intro to Relational Model

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

The Relational Model 2. Week 3

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

Introduction to Database Systems. The Relational Data Model

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

CPS510 Database System Design Primitive SYSTEM STRUCTURE

Unit 4 SQL language: other definitions

Let s briefly review important EER inheritance concepts

Database Management System 9

The Relational Model

Relational Data Model. Christopher Simpkins

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

Detailed Data Modelling. Detailed Data Modelling. Detailed Data Modelling. Identifying Attributes. Attributes

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

CS430 Final March 14, 2005

In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes)

Example Examination. Allocated Time: 100 minutes Maximum Points: 250

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

Database Design Process

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

CSE532 Theory of Database Systems The Relational a Data Model

Database Systems External Sorting and Query Optimization. A.R. Hurson 323 CS Building

Chapter 2 Introduction to Relational Models

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

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Class Information. Textbooks. Grading. Final Project. Grading. CS 440: Database Management Systems. Instructor:

A database consists of several tables (relations) AccountNum

Transcription:

Relational Model A.R. Hurson 323 CS Building

Relational data model Database is represented by a set of tables (relations), in which a row (tuple) represents an entity (object, record) and a column corresponds to an attribute of an entity. Schema A description of a particular collection of data using a given data model.

Levels of abstraction Conceptual (logical) level describes stored data in terms of the data model s conceptual data base design (defines entities, attributes, and relationships). This provides physical data independence. Physical level specifies additional storage details. In another words, it is the realization of conceptual schema level. External level (user s view of data), this provides logical data independence.

A relational database is a collection of relations. A relation corresponds to an entity which is referred to as a table (a collection of rows of the same structure. It is a two dimensional array (m * n) of m distinct rows and n columns. m is called the cardinality and n is called the degree (arity).

A tuple corresponds to each row of the table, it is a collection of n attributes. The primary key is an identifier for the table, a column or a collection of columns, that uniquely identifies each tuple.

Domain is a pool of values from which one or more attributes draw their actual values. In another words, a domain is a collection of smallest semantic unit of data (Scalar data). A domain is a set of scalar values of the same type. Note at this point we assume that a domain does not contain a null element (this will be relaxed later). A domain can be classifies as: Simple domain Complex domain

Simple domain: Domains of scalar values, Complex domain: domains. A collection of simple Note: if two attributes draw their values from the same domain, then it make sense to perform various operations (such as comparison, join, ) involving these two attributes.

Relation: A relation R on a set of domains D 1, D 2,, D n (not necessarily all distinct) is a subset of Cartesian products of D 1, D 2,, D n. R D 1 * D 2 *. * D n In another words, R is a collection of tuples each of n elements (a i 1 i n) where a i D i for 1 i n.

A relation consists of two parts: Heading (Schema, relation schema) Column heads: consists of a fixed set of attributes, more precisely, attribute domain pairs; {(A 1 :D 1 ), (A 2 :D 2 ),, (A n :D n )}, where A is are distinct. A schema represents the relation name, name of each attributes and the domain of each attribute. Students (Sid:string, name:string, login:string, age:integer, gpa:real)

Body (relation instance): consists of a timevarying set of tuples. Each tuple consists of a set of attribute value pairs. {(A 1 :vi 1 ), (A 2 :vi 2 ),, (A n :vi n )} Note cardinality of a relation may change in time, but its degree (arity) does not.

For example: S# Sname Status City S 1 Smith 20 London S 2 Jones 10 Paris S 3 Blake 30 Paris S 4 Clark 20 London S 5 Adams 30 Athens

The previous example shows a relation with cardinality of 5 and degree of 4. Each row represents a tuple and each column represents an attribute. Furthermore, each column draw its value from its domain.

Refer to our previous example: City is an attribute that draws its values from a domain which contains London London Paris, etc. Similarly, S# draws its value from a domain which contains S 1, S 2, S 3 S 4, S 5, etc.

Properties of relations: There is no duplicated tuples. No two rows are identical there is always a primary key. Tuples are unordered. Attributes are unordered. All attribute values are atomic (we might relax this later).

Formally, let R (f 1 :D 1 ), (f 2 :D 2 ),, (f n :D n ) be a relation schema and for each f i (1 i n) let Dom i be the set of values associated with the domain D i. An instance of R that satisfies the domain constraints in the schema is a set of tuples (a relation) with n fields: {<f 1 :d 1 >,<f 2 :d 2 >,,<f n :d n > d 1 Dom 1,d 2 Dom 2,,d n Dom n } <Sid:5,000>,<name:Dave>,<login:dave@cse.psu.edu>, <age:23>,<gpa:3.45> is a tuple.

Kinds of relations: Base relation is a relation that is sufficiently important (carry important information) that the database designer has decided to made it a part of the database. View is a derived relation, it does not have any separate, distinguishable stored data of its own (logical relation). Snapshot like a view is a derived relation. However, unlike view, a snapshot is real and not virtual it is defined by its definition and its own stored data.

Query result is an output relation resulting from some specified query. Intermediate result is a relation that is the result of a relational expression nested within larger expression. Temporary relation is a base, view, or snapshot created during the course of operations and destroyed automatically at some appropriate time by the system.

Database schema: Description of database is called database schema. Database schema is defined during database design and usually is not going to change frequently.

Transaction is a sequence of operations that transfers database from one consistent state to another consistent state. A transaction can be looked at as a collection of read and write operations terminated by a commit or abort operation.

To provide a timely access to information, a database management system should interleave several transactions and allow concurrent execution of transactions. This also means that proper concurrency rules (constraints) must be applied so that each transaction appears to execute in isolation.

In general, a database management system should guarantee ACID property of a transaction (Atomicity, Consistency, Isolation, Durability):

Atomicity: Either all operations of a transaction happen or none happen. State changes in a transaction are atomic. Consistency: A transaction produces results consistent with integrity requirements of the database. Isolation: In spite of the concurrent execution of transactions, each transaction believes it is executing in isolation. Intermediate results of a transaction should be hidden from other concurrently executing transactions. Durability: On successful completion of a transaction, the effects of the transaction should survive failures.

Integrity Rules The database definition needs to be extended to include certain constraints (integrity rules reliable operations). In the real world, for example, weight cannot be negative. Integrity rules are needed so that it can prevent such impossible configuration of values from occurring.

Integrity Rules Most databases will be subject to a very large number of such integrity rules. Note that most of the integrity rules are specific in the sense that they are applied to one specific database.

Integrity Rules In this section, we will discuss about three general integrity rules that applies to every databases. Note, the integrity rules both general and specific are defined for base relations.

Integrity Rules Consider the following three relations. Note that Primary key is allowed to be composite. It is possible to have all the attributes of the relation to represent the primary key All key relation. It is also possible for a relation to have more than one unique identifiers Multiple candidate keys. In this case, one of the candidate keys will be chosen as the primary key and the rest will be chosen as alternative keys.

Integrity Rules S# Sname Status City S 1 Smith 20 London S 2 Jones 10 Paris S 3 Blake 30 Paris S 4 Clark 20 London S 5 Adams 30 Athens

Integrity Rules P# Pname Color Weight City P 1 Nut Red 12 London P 2 Bolt Green 17 Paris P 3 Screw Blue 17 Rome P 4 Screw Red 14 London P 5 Cam Blue 12 Paris P 6 Cog Red 19 London

Integrity Rules S# P# QTY S 1 P 1 300 S 1 P 2 200 S 1 P 3 400 S 1 P 4 200 S 1 P 5 100 S 1 P 6 100 S 2 P 1 300 S 2 P 2 400 S 3 P 2 200 S 4 P 2 200 S 4 P 4 300 S 4 P 5 400

Integrity Rules Candidate Key: Attribute K (possibly composite) of relation R is a candidate key for R, if and only if it satisfies the following two time-independent properties: Uniqueness: At any point in time, no two tuples of R have the same value for K. Minimality: If K is composite, then no components of K can be eliminated without destroying the uniqueness property.

Integrity Rules No component of the primary key of a base relation is allowed to be null (undefined). This may not be applied to alternative keys. Primary key allows associative addressing.

Integrity Rules Foreign Key is an attribute of a relation R 2 (possibly composite) whose values are required to match those of the primary key of another relation R 1. A foreign key is a mechanism to establish references between two relations. This brings an issue know as the referential integrity. Attributes S# and P#, for SP relation, are examples of foreign keys.

Integrity Rules Attribute FK (possibly composite) of base relation R 2 is a foreign key, if and only if it satisfies the following time-independent properties: Each value of FK is either wholly null or wholly non-null (all null or none null). There exists a base relation R 1 (target relation) with primary key PK such that each non-null value of FK is identical to the value of PK in some tuple of R 1.

Integrity Rules A foreign key value represents a reference to the tuple containing the matching primary key value. The relation that contains the foreign key is the referencing relation and the relation that contains the corresponding primary key is the target (referenced) relation. In our example: Referential diagram S SP P

Integrity Rules In the following example: DEPT ( DEPT#,, BUDGET, ) EMP ( EMP#,, DEPT#,, SALARY, ) DEPT# is the foreign key in EMP relation and it is not a part of the primary key of EMP relation. DEPT EMP A relation cab be both a referenced relation and referencing relation. R 3 R 2 R 1

Integrity Rules Referential Integrity rule: The database must not contain any unmatched foreign key value. Foreign key rules: At each moment in time, the database should be in a valid state and any transaction should transfer the database from a valid state to another valid state. Therefore, for an operation that violates these constraints, either the operation should be denied, or the database automatically, should generate a compensating operation.

Questions Can a foreign key accept nulls? What should happen on an attempt to delete the target of a foreign key reference? What should happen on an attempt to update the primary key of the target of a foreign key reference?

General Constraints To preserve data integrity, we may need to define domain specific integrity rules. These rules can be enforced in the form of table constraints or assertions. Table constraints are defined for each relation and are enforced whenever contents of the relation is modified (insert, delete, update). Assertions involve several relations and are enforced whenever any of these relations is modified.