Lecture #11 Relational Database Systems KTH ROYAL INSTITUTE OF TECHNOLOGY

Similar documents
14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

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

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

Files. Files. Files. Files. Files. File Organisation. What s it all about? What s in a file?

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

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

... Chair of Mobile Business & Multilateral Security. Lecture 11 Business Informatics 2 (PWIN)


In This Lecture. Physical Design. RAID Arrays. RAID Level 0. RAID Level 1. Physical DB Issues, Indexes, Query Optimisation. Physical DB Issues

IT2304: Database Systems 1 (DBS 1)

Databases and BigData

Lecture 6. SQL, Logical DB Design

5.5 Copyright 2011 Pearson Education, Inc. publishing as Prentice Hall. Figure 5-2

DBMS / Business Intelligence, SQL Server

Foundations of Information Management

IT2305 Database Systems I (Compulsory)

2. Background on Data Management. Aspects of Data Management and an Overview of Solutions used in Engineering Applications

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

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

DATABASE INTRODUCTION

CSC 742 Database Management Systems

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

Normalisation to 3NF. Database Systems Lecture 11 Natasha Alechina

Intro to Databases. ACM Webmonkeys 2011

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

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

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

Information Systems Modelling Information Systems I: Databases

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

2) What is the structure of an organization? Explain how IT support at different organizational levels.

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

CHAPTER 5: BUSINESS ANALYTICS

Data. Data and database. Aniel Nieves-González. Fall 2015

The Entity-Relationship Model

COMHAIRLE NÁISIÚNTA NA NATIONAL COUNCIL FOR VOCATIONAL AWARDS PILOT. Consultative Draft Module Descriptor. Relational Database

MODULE 8 LOGICAL DATABASE DESIGN. Contents. 2. LEARNING UNIT 1 Entity-relationship(E-R) modelling of data elements of an application.

BCA. Database Management System

1 Structured Query Language: Again. 2 Joining Tables

Introduction to Databases

Relational Data Analysis I

Relational Database Basics Review

Database Design and Programming

THE BCS PROFESSIONAL EXAMINATION Diploma. October 2004 EXAMINERS REPORT. Database Systems

Foundations of Business Intelligence: Databases and Information Management

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University

Unit Storage Structures 1. Storage Structures. Unit 4.3

ENHANCEMENTS TO SQL SERVER COLUMN STORES. Anuhya Mallempati #

In-Memory Data Management for Enterprise Applications

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

low-level storage structures e.g. partitions underpinning the warehouse logical table structures

CHAPTER 4: BUSINESS ANALYTICS

Modern Systems Analysis and Design

TIM 50 - Business Information Systems


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

Overview. Physical Database Design. Modern Database Management McFadden/Hoffer Chapter 7. Database Management Systems Ramakrishnan Chapter 16

Database Management. Technology Briefing. Modern organizations are said to be drowning in data but starving for information p.

1 File Processing Systems

Data Analysis 1. SET08104 Database Systems. Napier University

Foundations of Information Management

Normalization. Reduces the liklihood of anomolies

Objectives of Lecture 1. Labs and TAs. Class and Office Hours. CMPUT 391: Introduction. Introduction

Chapter 5. SQL: Queries, Constraints, Triggers

IS466 Decision Support Systems. SQL Server Business Intelligence Development Studio 2008 User Guide

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

3. Relational Model and Relational Algebra

EECS 647: Introduction to Database Systems

Foundations of Business Intelligence: Databases and Information Management

CS 3719 (Theory of Computation and Algorithms) Lecture 4

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

Databases. DSIC. Academic Year

CS352 Lecture - Object-Based Databases

H4 DATABASE DEVELOPMENT SOLUTIONS & MARKING SCHEME JUNE 2013

Zero Downtime Deployments with Database Migrations. Bob Feldbauer

Fundamentals of Database Design

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

1. INTRODUCTION TO RDBMS

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

Database Systems. Lecture 1: Introduction

Data Hierarchy. Traditional File based Approach. Hierarchy of Data for a Computer-Based File

n Assignment 4 n Due Thursday 2/19 n Business paper draft n Due Tuesday 2/24 n Database Assignment 2 posted n Due Thursday 2/26

Database-driven library system

Data Modeling Basics

Entity/Relationship Modelling. Database Systems Lecture 4 Natasha Alechina

Chapter 1: Introduction

LOGICAL DATABASE DESIGN

INFO/CS 330: Applied Database Systems

Course MIS. Foundations of Business Intelligence

Chapter 6 FOUNDATIONS OF BUSINESS INTELLIGENCE: DATABASES AND INFORMATION MANAGEMENT Learning Objectives

Alexander Nikov. 5. Database Systems and Managing Data Resources. Learning Objectives. RR Donnelley Tries to Master Its Data

Introduction to Object-Oriented and Object-Relational Database Systems

Basic Concepts of Database Systems

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

Exercise 1: Relational Model

Literature for the 1 st part

7. Databases and Database Management Systems

Databases in Organizations

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

CSE 132A. Database Systems Principles

Transcription:

Lecture #11 Relational Database Systems KTH ROYAL INSTITUTE OF TECHNOLOGY

Contents Storing data Relational Database Systems Entity Relationship diagrams Normalisation of ER diagrams Tuple Relational Calculus

Storing data persistently XML file CSV file Objects Java App DBMS CPU DB RAM HDD During execution, RAM is used to store our data Files can be read and write for persistent storage But what if we want to access the data in a more flexible way? Reading single posts, adding data, removing data etc.

Databases Database Management Systems (DBMS) The idea of data storage developed gradually when computing capabilities grew file storage was simply not enough Various models to link and index that data were developed: Hierarchical storage (Tree-like struture) Network storage (cross references between data items) Relational storage (the winning model, used presently)

Relational data storage Data is organised in tables of two dimensions Rows & Columns Tables are known as Relations Rows are Tuples Columns are Attributes ID Name Grade 1 Jill D 2 Bob B 3 Steve C

Cardinality & Degree Attributes ID Name Grade 1 Jill D Tuples 2 Bob B 3 Steve C The cardinality of a Relation is its number of tuples (rows) The degree of a Relation is its number of attributes (columns)

What are these tables really? 1. Data is stored on the computer s HDD as bits (of course) 2. The data is struuctred according to some scheme that is efficient for the disk and CPU s access to the data 3. When we people want to write a (Java) program to manipulate the data, we think of it, and access it in the form of tables 4. The DBMS program translate from the tables to actual data storage (which is logical to the CPU but not to us) XML file CSV file Objects Java App DBMS CPU DB RAM HDD

Contents Storing data Relational Database Systems Entity Relationship diagrams Normalisation of ER diagrams Tuple Relational Calculus

Entity Relationship Diagrams Relations between Relations By defining attributes as Keys we can relate Tuples from different Relations to each other.

E-R diagrams vs. Class diagrams But aren t E-R diagrams the same as Class diagrams??? In a way, they are very similar, but ER only data, no methods ER No OO concepts (inheritance, aggregation, etc.) Classes No Keys

Contents Storing data Relational Database Systems Entity Relationship diagrams Normalisation of ER diagrams Tuple Relational Calculus

Good relations Is this a good relation? Part Qt Warehouse Adress Wheel 23 Building2 Main St 12 Wheel 12 Building1 Diagon Alley 3 Seat 9 Building1 Diagon Alley 3 Is this a good relation?

E-R Diagrams must be Normalised Normalisation of E-R diagrams is like Good Programming Style but for Data It enables more efficient access to data and more efficient storage Reduces the risk of error in data. In Theory 5 levels of Normality (or Normal forms) exist 1st Normal form 2nd Normal form 3rd Normal Form We stop here 4th Normal Form 5th Normal Form

First Normal Form The First Normal is basic housekeeping. All Tuples in a Relation must have the same number of attributes. Or The degree of all Tuples must be the same. This borders on the obvious under the definition of a Relational Database, since this is the definition of a Relation

Second Normal Form Only relevant when the keys are composite, i.e., consists of several attributes To fulfill Second normal form non-key fields cannot have facts about a part of a key. Warehouse Part Adress Qt Building2 Wheel Main St 12 23 Building1 Wheel Diagon Alley 3 12 Building1 Seat Diagon Alley 3 9 Keys

Normalised to 2nd Normal Form Warehou se Part Qt Building2 Wheel 23 Building1 Wheel 12 Building1 Seat 9 Keys Warehouse Adress Building1 Diagon Alley 3 Building2 Main St 12

Third Normal Form In Third Normal Form, a non-key attribute must not hold information about another non-key attribute Course Professor Office EH2745 Nordström Osquldas väg 10, floor 7 EH2751 Nordström Osquldas väg 10, floor 7 EJ2301 Soulard Teknikringen 33, floor 1 EG2200 Amelin Reknikringen 35, floor 2 Key

Normalised to 3rd Normal form Course Professor EH2745 Nordström Professor Office EH2751 EJ2301 EG2200 Nordström Soulard Amelin Nordström Amelin Osquldas väg 10, floor 7 Teknikringen 33, floor 2 Soulard Teknikringen 33, floor 1

Contents Storing data Relational Database Systems Entity Relationship diagrams Normalisation of ER diagrams Tuple Relational Calculus

Tuple Relational Calculus With the definitions (Relation, Tuple, Attribute) above we can define a number of basic operations on relations Insert Delete Update Select Project Join Union Intersection Difference

Insert Insert is a unary operation it operates on a single Relation It adds a Tuple to a Relation ID Name Grade 1 Jill D 2 Bob B 3 Steve C ID Name Grade Insert t in R 1 Jill D 2 Bob B 3 Steve C 4 Lars A

Delete Delete is a unary operation it operates on a single Relation It deletes a Tuple fulfilling criteria from a Relation ID Name Grade 1 Jill D 2 Bob B 3 Steve C 4 Lars A ID Name Grade 1 Jill D Delete t where a=x from R 2 Bob B 4 Lars A

Update Update is a unary operation it operates on a single Relation It modifies an attribute in Tuple fulfilling criteria in a Relation ID Name Grade 1 Jill D 2 Bob B 4 Lars A ID Name Grade 1 Jill D 2 Bob B 4 Lars E Update t.a2=data where t.a1=x in R

Select Select is a unary operation it operates on a single Relation The Select operation creates a new relation R2 from relation R1 The Tuples inr1 is a subset of R2 ID Name Grade 1 Jill D 2 Bob B 4 Lars E ID Name Grade 2 Bob B 4 Lars E Select * from R1 where ID >1

Project Project is a unary operation it operates on a single Relation The Project operation creates a new relation R2 from relation R1 The Attributes in R1 is a subset of R2 ID Name Grade 1 Jill D 2 Bob B 4 Lars E Name Jill Bob Project Name from R1 Lars

Join Join is a binary operation it operates two Relations The Join operation creates a new relation R3 from relations R1 & R2 Based on common attributes (keys) Course Professor EH2745 EH2751 EJ2301 EG2200 Nordström Nordström Soulard Amelin Not Normalised?? Course Professor Office X EH2745 Nordström Osquldas väg 10, floor 7 EH2751 Nordström Osquldas väg 10, floor 7 Professor Office EJ2301 Soulard Teknikringen 33, floor 1 Nordström Osquldas väg 10, floor 7 Amelin Teknikringen 33, floor 2 Soulard Teknikringen 33, floor 1 EG2200 Amelin Reknikringen 35, floor 2 Intermediate result for analysis

Union A binary operation it operates on two Relations R1 and R2 Creates a new relation R3 in which each tuple is either in R1, in the R2, or in both R1 and R2. The two relations must have the same attributes. Warehouse Adress Building3 King St 23 Building4 Queens Rd 2 Warehouse Adress Warehouse + Adress Building1 Diagon Alley 3 Building2 Main St 12 Building3 King St 23 Building4 Queens Rd 2 Building1 Diagon Alley 3 Building2 Main St 12

Intersection A binary operation it operates on two Relations R1 and R2 Creates a new relation R3 in which each tuple is in both R1 and R2. The two relations must have the same attributes. Warehouse Adress Building1 Diagon Alley 3 Building4 Queens Rd 2 Warehouse Adress Building1 Diagon Alley 3 Warehouse Adress Building1 Diagon Alley 3 Building2 Main St 12

Difference A binary operation it operates on two Relations R1 and R2 Creates a new relation R3 in which each tuple is in R1 but not in R2. The two relations must have the same attributes. Warehouse Adress Building1 Diagon Alley 3 Building4 Queens Rd 2 - Warehouse Adress Building4 Queens Road 2 Warehouse Adress Building1 Diagon Alley 3 Building2 Main St 12

Contents Storing data Relational Database Systems Entity Relationship diagrams Normalisation of ER diagrams Tuple Relational Calculus Now you can try this with SQL in MySQL