Course 2. The Relational Model

Similar documents
CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

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

The Relational Model. Why Study the Relational Model?

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

Lecture 6. SQL, Logical DB Design

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Database Management Systems. Chapter 1

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

EECS 647: Introduction to Database Systems

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

ECS 165A: Introduction to Database Systems

COMP5138 Relational Database Management Systems. Databases are Everywhere!

Data Modeling. Database Systems: The Complete Book Ch ,

Introduction to Databases

Topics. Introduction to Database Management System. What Is a DBMS? DBMS Types

Databases and BigData

There are five fields or columns, with names and types as shown above.

The Relational Data Model and Relational Database Constraints

SQL NULL s, Constraints, Triggers

Database Systems. Lecture 1: Introduction

Overview. Introduction to Database Systems. Motivation... Motivation: how do we store lots of data?

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Fundamentals of Database Design

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

How To Manage Data In A Database System

Databases What the Specification Says

Introduction to Database Systems. Module 1, Lecture 1. Instructor: Raghu Ramakrishnan UW-Madison

3. Relational Model and Relational Algebra

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Introduction to Database Systems CS4320. Instructor: Christoph Koch CS

2. Basic Relational Data Model

Review: Participation Constraints

Section of DBMS Selection & Evaluation Questionnaire

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

BCA. Database Management System

Relational Databases


In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Instant SQL Programming

1 File Processing Systems

How To Create A Table In Sql (Ahem)

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Chapter 1: Introduction

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

IT2304: Database Systems 1 (DBS 1)

Basic Concepts of Database Systems

The Entity-Relationship Model

Chapter 5. SQL: Queries, Constraints, Triggers

IT2305 Database Systems I (Compulsory)

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

The SQL Query Language. Creating Relations in SQL. Referential Integrity in SQL. Basic SQL Query. Primary and Candidate Keys in SQL

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Lesson 8: Introduction to Databases E-R Data Modeling

CSC 443 Data Base Management Systems. Basic SQL

Winter Winter

æ A collection of interrelated and persistent data èusually referred to as the database èdbèè.

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Course: CSC 222 Database Design and Management I (3 credits Compulsory)

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

4 Logical Design : RDM Schema Definition with SQL / DDL

Chapter 1: Introduction

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

1. INTRODUCTION TO RDBMS

SQL: Queries, Programming, Triggers

Relational Algebra and SQL

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

In This Lecture. Security and Integrity. Database Security. DBMS Security Support. Privileges in SQL. Permissions and Privilege.

The process of database development. Logical model: relational DBMS. Relation

The core theory of relational databases. Bibliography

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

SQL: Queries, Programming, Triggers

The Relational Data Model: Structure

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Relational Database Basics Review

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Chapter 2 Database System Concepts and Architecture

Introduction to SQL ( )

Ch.5 Database Security. Ch.5 Database Security Review

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Database Systems Introduction Dr P Sreenivasa Kumar

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

SQL Server. 1. What is RDBMS?

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

7. Databases and Database Management Systems

Chapter 1: Introduction. Database Management System (DBMS)

Overview of Database Management Systems

Maintaining Stored Procedures in Database Application

Databases in Engineering / Lab-1 (MS-Access/SQL)

Exercise 1: Relational Model

CSE 233. Database System Overview

Logical Schema Design: The Relational Data Model

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Database Security. Chapter 21

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

Transcription:

Course 2. The Relational Model Layered Approach to Database Implementation Figure 2.1. Levels of Abstraction: - Views describe how users see the data - Conceptual schema defines logical structure - Physical schema describes the files and indexes used Example: Faculty database Conceptual schema: Students(sid:string, name:string, email:string, age:integer, gr:integer) Courses(cid: string, cname: string, credits:integer) Exams(sid:string, cid:string, grade:integer) Physical schema: Relations stored as unordered files. Index on first column of Students. Figure 2.2. External Schema (View): Course_info(cid:string, enrollment:integer) One of the most important benefits of using a DBMS is that the applications are isolated from how

data is structured and stored. - Logical data independence: Protection from changes in logical structure of data. - Physical data independence: Protection from changes in physical structure of data. Queries in a DBMS For the sample Faculty Database, here are some questions that users may ask: - What is the name of the student with sid 2833? - What is the salary of the professor who teaches the course with cid Alg100? - How many students are enrolled in course Alg100? Such questions involving data stored in a DBMS are called queries. A DBMS provides a specialized language, called the query language, in which queries can be posed. Each query language is composed by: - Data Definition Language (DDL) o Used to define the conceptual and internal schemas; o Includes constraint definition language (CDL) for describing conditions that database instances must satisfy; o Includes storage definition language (SDL) to influence layout of physical schema (some DBMSs); - Data Manipulation Language (DML) o o Used to describe operations on the instances of a database Procedural DML (how) vs. declarative DML (what). Query Languages for Relational DBs SQL (Structured Query Language): SELECT name FROM Students WHERE age > 20 Algebra: name( age > 20 (Students)) Domain Calculus: {<X> V Y Z T : Students(V, X, Y, Z, T) Z>20} T-uple Calculus: {X Y : Y Students Y.age > 20 X.name =Y.name} Databases related actors - System Analyst: Designs entity-relationship diagram

- Database Designer: Designs logical /physical schemas - Application Programmer - Database Administrator o Handles security and authorization o Data availability, crash recovery o Database tuning as needs evolve - System Administrator - End Users (Naive / Sophisticated end users) Relational Model Use a simple data structure: the Table - simple to understand - useful data structure (capture many situations) - leads to useful not too complex query lang. Use mathematics to describe and represent records and collections of records: the Relation - can be understood formally - leads to formal query languages - properties can be explained and proven Relation formal definition A domain is a set of scalar values (i.e. limited to atomic types - integer, string, boolean, date, blobs). A relation or relation schema R is a list of attribute names [A1, A2,, An]. Di = Dom(Ai) - domain of Ai, i=1..n Relation instance ([R]) is a subset of D1 D2 Degree (arity) = the number of attributes in a relation scheme Tuple = an element of the relation instance, a record. All tuples of a relation are distinct! Cardinality = the number of tuples of a relation n Relation example

Very often we will confuse - the relation, its schema, and its instance - the instance and the table - the attribute, the field and the column - the tuple, the record and the row Ask for precision if there is ambiguity! A database is a set of relations. A database schema is the set of schemas of the relations in the database. A database instance (state) is the set of instances of the relations in the database. Integrity Constraints Integrity Constraints (ICs) are conditions that must be true for any instance of the database. ICs are specified when schema is defined and are checked when relations are modified. A legal instance of a relation is one that satisfies all specified ICs. Integrity Constraints samples: Students(sid:string, name:string, email:string, age:integer, gr:integer) Domain constraints: gr:integer Range constraints: 18 age 70 TestResults(sid:string, TotalQuestions:integer, NotAnswered:integer, CorrectAnswers:integer,

WrongAnswers:integer) TotalQuestions = NotAnswered+CorrectAnswers+WrongAnswers not an IC! Primary Key Constraint A set of fields is a key for a relation if : 1. No two tuples can have same values for all fields AND 2. This is not true for any subset of the key. If the 2 nd statement is false superkey. If there s >1 key for a relation candidate keys One of the candidate keys is chosen as primary key Foreign Keys, Referential Integrity A foreign key is a set of fields in one relation that is used to `refer to a tuple in another relation (Like a `logical pointer ) It must correspond to primary key of the second relation. E.g. sid is a foreign key referring to Students: Enrolled (sid: string, cid: string, grade: double) Referential integrity = all foreign key constraints are enforced no dangling references. Let s consider Students and Enrolled tables: sid in Enrolled is a foreign key that references a record from Students table. What should be done if an Enrolled record with a non-existent student id is inserted? The DBMS will reject it. What should be done if a Students tuple is deleted? There are 4 approaches: - Also delete all Enrolled tuples that refer to it. - Disallow deletion of a Students tuple that is referred to. - Set sid in Enrolled tuples that refer to it to a default sid. - Set sid in Enrolled tuples to a special value null, denoting `unknown or `inapplicable. The same approaches we have if primary key of Students tuple is updated.

Figure 2.3. Samples of graphical representation of tables, fields, primary keys and foreign keys in Keys and foreign keys are the most common ICs. ICs are based upon the semantics of the real-world enterprise that is being described in the database relations. We can check a database instance to see if an IC is violated, but we can NEVER infer that an IC is true by looking at an instance. An IC is a statement about all possible instances of a particular table! For example, for Students table we know name is not a key, but the assertion that sid is a key is given to us. Relational Query Languages A major strength of the relational model is that it supports simple, powerful querying of data. Queries can be written intuitively, and the DBMS is responsible for efficient evaluation. - The key: precise semantics for relational queries. - Allows the optimizer to extensively re-order operations, and still ensure that the answer does not change.

Structured Query Language (SQL) became de-facto standard for query languages based on the relational data model. It was developed by IBM (system R) in the 1970. It was a need for a standard since it is used by many vendors SQL Standards: - SQL-86 - SQL-89 (minor revision) - SQL-92 (major revision) - 1,120 pages - SQL-99 (major extensions) - 2,084 pages - SQL-2003 (SQL/XML new section) - 3,606 pages - SQL-2008 - SQL- 2011 SQL Levels Data-definition language (DDL): - Create / destroy / alter relations and views. - Define integrity constraints (IC s). Data-manipulation language (DML) - Allows users to pose queries - Insert /delete / modify (update) tuples. Access Control: - Can grant / revoke the right to access and manipulate tables (relations / views).