CS275 Intro to Databases

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

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

CS 377 Database Systems

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

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

The Relational Data Model and Relational Database Constraints

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Relational Data Model. Christopher Simpkins

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

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

CSE 132A Database Systems Principles

Chapter 3 Outline. Relational Model Concepts. The Relational Data Model and Relational Database Constraints Database System 1

CSC 742 Database Management Systems

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

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

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

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

CS 2451 Database Systems: Relational Data Model

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 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. Why Study the Relational Model? Relational Database: Definitions

Relational Model and Relational Algebra

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

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

The Relational Model of Data (ii)

Relational data model

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

The Relational Data Model. Data Model

Chapter 4. The Relational Model

Database Management Systems. Chapter 3 Part 1

CS2300: File Structures and Introduction to Database Systems

ECE 650 Systems Programming & Engineering. Spring 2018

The Relational Data Model and Relational Database Constraints

Let s briefly review important EER inheritance concepts

The Relational Model. Week 2

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

The Relational Model

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

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

A database consists of several tables (relations) AccountNum

The Relational Model. Chapter 3

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

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

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

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

The Relational Model Constraints and SQL DDL

CSIT5300: Advanced Database Systems

The Relational Data Model (ALL the Vocabulary)

Introduction to Databases

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

Databases. Jörg Endrullis. VU University Amsterdam

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

Database Applications (15-415)

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

Introduction to Database Systems. The Relational Data Model

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

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

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

Relational Database Systems Part 01. Karine Reis Ferreira

Database Management System 9

The Relational Model 2. Week 3

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

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

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

Running Example Tables name location

Chapter 1: Introduction

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Database Systems ( 資料庫系統 )

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

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

Database Technology. Topic 2: Relational Databases and SQL. Olaf Hartig.

DATABASE TECHNOLOGY - 1DL124

Chapter 2: Intro to Relational Model

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

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

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

The Relational Model and Relational Algebra

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

The Relational Model

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

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

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

Chapter 2: Intro to Relational Model

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

DATABASE DESIGN I - 1DL300

Chapter 2 Introduction to Relational Models

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

CompSci 516 Database Systems. Lecture 2 SQL. Instructor: Sudeepa Roy

Relational Model Concepts

Introduction to Database Management Systems

Relational Model. CS 377: Database Systems

Chapter 8 INTEGRITY 1

The Relational Model

Lecture 2 SQL. Announcements. Recap: Lecture 1. Today s topic. Semi-structured Data and XML. XML: an overview 8/30/17. Instructor: Sudeepa Roy

Relational Model and Relational Algebra. Rose-Hulman Institute of Technology Curt Clifton

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

9/8/2018. Prerequisites. Grading. People & Contact Information. Textbooks. Course Info. CS430/630 Database Management Systems Fall 2018

The Entity Relationship Model

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

Transcription:

CS275 Intro to Databases The Relational Data Model Chap. 3 How Is Data Retrieved and Manipulated? Queries Data manipulation language (DML) Retrieval Add Delete Update An Example UNIVERSITY database Information concerning students, courses, and grades in a university environment Data records STUDENT COURSE SECTION GRADE_REPORT PREREQUISITE 1

An Example (cont'd.) Specify structure of records of each file by specifying data type for each data element String of alphabetic characters Integer Etc. Student(name: string, snum: integer, class: string, major: string) Course(cname: string, cnum: string, credits: integer, dept: string) Grade_Report(snum: integer, sid: integer, grade: string) Section(sid: integer, cnum: string, sem: string, year: integer, instr: string) Etc. An Example (cont'd.) Construct UNIVERSITY database Store data to represent each student, course, section, grade report, and prerequisite as a record in appropriate file Relationships among the records Manipulation involves querying and updating 2

An Example (cont'd.) Examples of queries: Retrieve the transcript List the names of students who took the section of the Database course offered in fall 2008 and their grades in that section List the prerequisites of the Database course An Example (cont'd.) Examples of updates: Change the class of Smith to sophomore Create a new section for the Database course for this semester Enter a grade of A for Smith in the Database section of last semester Self Describing Nature of a Database System Database system contains complete definition of structure and constraints Meta data Describes structure of the database Database catalog used by: DBMS software Database users who need information about database structure 3

Relational Model Concepts Collection of relations Table of values Row Tuple of related data values How are the data values related? Table name What is the purpose of this? Column names Attributes providing meaning for the values 4

Relational Model Concepts (cont d.) What are other possible relations in our University database? Domains, Attributes, Tuples, and Relations Domain D Set of atomic values Each value indivisible Atomic Each value indivisible Specifying a domain Name Data type Format Ex. Create domain ssn_type as char(9) Domains, Attributes, Tuples, and Relations (cont d.) Relation schema R Denoted by R(A 1, A 2,...,A n ) Made up of a relation name R and a list of attributes, A 1, A 2,..., A n Attribute A i Name of a role played by some domain D in the relation schema R Degree (or arity) of a relation Number of attributes n of its relation schema 5

Domains, Attributes, Tuples, and Relations (cont d.) Relation (or relation state) Set of n tuples r = {t 1, t 2,..., t m } Each n tuple t Ordered list of n values t =<v 1, v 2,..., v n Each value v i, 1 i n, is an element of dom(a i ) or is a special NULL value Domains, Attributes, Tuples, and Relations (cont d.) Relation (or relation state) r(r) Subset of the Cartesian product of the domains that define R: r(r) (dom(a 1 ) dom(a 2 )... dom(a n )) Cardinality Total number of values in domain What would be the cardinality for the ssn_type domain? Characteristics of Relations Ordering of tuples in a relation Relation defined as a set of tuples Elements have no order among them Ordering of values within a tuple and an alternative definition of a relation Order of attributes and values is not that important As long as correspondence between attributes and values maintained 6

Characteristics of Relations (cont d.) Alternative definition of a relation Tuple considered as a set of (<attribute>, <value>) pairs Each pair gives the value of the mapping from an attribute A i to a value v i from dom(a i ) Use the first definition of relation Attributes and the values within tuples are ordered Simpler notation Why might it be helpful to think of the tuples as an unordered set of pairs? Characteristics of Relations (cont d.) Values and NULLs in tuples Each value in a tuple is atomic Flat relational model Composite and multivalued attributes not allowed First normal form assumption Multivalued attributes Must be represented by separate relations Composite attributes Represented only by simple component attributes in basic relational model Characteristics of Relations (cont d.) NULL values Represent the values of attributes that may be unknown or may not apply to a tuple Meanings for NULL values Value unknown Value exists but is not available (or withheld) Attribute does not apply to this tuple (undefined) Be careful with NULL values 7

Relational Model Notation Relation schema R of degree n Denoted by R(A 1, A 2,..., A n ) Uppercase letters Q, R, S Denote relation names Lowercase letters q, r, s Denote relation states Letters t, u, v Denote tuples Relational Model Notation Name of a relation schema: STUDENT Indicates the current set of tuples in that relation Notation: STUDENT(Name, Ssn,...) Refers only to relation schema Attribute A can be qualified with the relation name R to which it belongs Using the dot notation R.A Relational Model Notation n tuple t in a relation r(r) Denoted by t = <v 1, v 2,..., v n > v i is the value corresponding to attribute A i Component values of tuples: t[a i ] and t.a i refer to the value v i in t for attribute A i t[a u, A w,..., A z ]and t.(a u, A w,..., A z )refer to the subtuple of values <v u, v w,..., v z > from t corresponding to the attributes specified in the list 8

Relational Model Constraints Constraints Restrictions on the actual values in a database state Derived from the rules in the miniworld that the database represents Inherent model based constraints or implicit constraints Inherent in the data model Relational Model Constraints (cont d.) Schema based constraints or explicit constraints Can be directly expressed in schemas of the data model Application based or semantic constraints or business rules Cannot be directly expressed in schemas Expressed and enforced by application program Domain Constraints Typically include: Numeric data types for integers and real numbers Characters Booleans Fixed length strings Variable length strings Date, time, timestamp Money Other special data types 9

Key Constraints and Constraints on NULL Values No two tuples can have the same combination of values for all their attributes. Superkey No two distinct tuples in any state r of R can have the same value for SK Key Superkey of R Removing any attribute A from K leaves a set of attributes K that is not a superkey of R any more Key Constraints and Constraints on NULL Values (cont d.) Key satisfies two properties: Two distinct tuples in any state of relation cannot have identical values for (all) attributes in key Minimal superkey Cannot remove any attributes and still have uniqueness constraint in above condition hold Key Constraints and Constraints on NULL Values (cont d.) Candidate key Relation schema may have more than one key Primary key of the relation Designated among candidate keys Underline attribute Other candidate keys are designated as unique keys 10

Key Constraints and Constraints on NULL Values (cont d.) Relational Databases and Relational Database Schemas Relational database schema S Set of relation schemas S = {R 1, R 2,..., R m } Set of integrity constraints IC Relational database state Set of relation states DB = {r 1, r 2,..., r m } Each r i is a state of R i and such that the r i relation states satisfy integrity constraints specified in IC Relational Databases and Relational Database Schemas (cont d.) Invalid state Does not obey all the integrity constraints Valid state Satisfies all the constraints in the defined set of integrity constraints IC 11

Integrity, Referential Integrity, and Foreign Keys Entity integrity constraint No primary key value can be NULL Referential integrity constraint Specified between two relations Maintains consistency among tuples in two relations Integrity, Referential Integrity, and Foreign Keys (cont d.) Foreign key rules: The attributes in FK have the same domain(s) as the primary key attributes PK Value of FK in a tuple t 1 of the current state r 1 (R 1 ) either occurs as a value of PK for some tuple t 2 in the current state r 2 (R 2 ) or is NULL Integrity, Referential Integrity, and Foreign Keys (cont d.) Diagrammatically display referential integrity constraints Directed arc from each foreign key to the relation it references All integrity constraints should be specified on relational database schema 12

Update Operations, Transactions, and Dealing with Constraint Violations Operations of the relational model can be categorized into retrievals and updates Basic operations that change the states of relations in the database: Insert Delete Update (or Modify) 13

The Delete/Update Operation Can violate referential integrity If tuple being deleted/updated is referenced by foreign keys from other tuples Restrict Reject the deletion/update Cascade Propagate the modification to tuples that reference the tuple that is being modified Set null or set default Modify the referencing attribute values that cause the violation 14