The Relational Model CS 186, Spring 2007, Lecture 2 Cow book Section 1.5, Chapter 3 Mary Roth.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 Introduction to Database Systems CSE444 Instructor: Scott Vandenberg University of Washington Winter 2000.
Database Management Systems 1 Ramakrishnan & Gehrke Introduction to Database Systems Chapter 1 Instructor: Mirsad Hadzikadic.
Database: A collection of related data [Elmasri]. A database represents some aspect of real world called “miniworld” [Elmasri] or “enterprise” [Ramakrishnan].
Introduction to Relational Databases Obtained from Portland State University.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
LBSC 690 Session #7 Structured Information: Databases Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under.
The Relational Model Ramakrishnan & Gehrke Chapter 3.
The Relational Model CS 186, Fall 2006, Lecture 2 R & G, Chap. 3.
The Relational Model CS 186, Spring 2006, Lecture 2 R & G, Chap. 1 & 3.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
The Relational Model Ramakrishnan & Gehrke, Chap. 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 1 Database Systems I Introduction.
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
On Database Systems.
1 Introduction to Database Systems Ref. Ramakrishnan & Gehrke Chapter 1.
1 CENG 302 Introduction to Database Management Systems Nihan Kesim Çiçekli URL:
CSCD34 - Data Management Systems,- A. Vaisman1 CSC D34 - Data Management Systems Instructor: Alejandro Vaisman University of Toronto.
Introduction to DBMS Purpose of Database Systems View of Data
1.1 CAS CS 460/660 Introduction to Database Systems Relational Model and more…
The Relational Model These slides are based on the slides of your text book.
CSC2012 Database Technology & CSC2513 Database Systems.
Data Models Amandeep Kaur Lecturer GPC Khunimajra Call at
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Introduction. 
Database Management Systems 1 Introduction to Database Systems Instructor: Xintao Wu Ramakrishnan & Gehrke.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
CS6530 Graduate-level Database Systems Prof. Feifei Li.
Database Management Systems 1 Ramakrishnan & Gehrke Introduction to Database Systems Chpt 1 Instructor: Xintao Wu.
Database Management Systems 1 Ramakrishnan & Gehrke Introduction to Database Systems Chpt 1 Instructor: Weichao Wang.
INFS614, Dr. Brodsky, GMU1 Database Management Systems INFS 614 Instructor: Professor Alex Brodsky
Introduction to Relational Databases
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Introduction to Database Systems1. 2 Basic Definitions Mini-world Some part of the real world about which data is stored in a database. Data Known facts.
The Relational Model Content based on Chapter 3 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
The Relational Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
1 CS462- Database Systems Sang H. Son
ASET 1 Amity School of Engineering & Technology B. Tech. (CSE/IT), III Semester Database Management Systems Jitendra Rajpurohit.
The Relational Model (cont’d) Introduction to Disks and Storage CS 186, Spring 2007, Lecture 3 Cow book Section 1.5, Chapter 3 (cont’d) Cow book Chapter.
Chapter 1: Introduction. 1.2 Database Management System (DBMS) DBMS contains information about a particular enterprise Collection of interrelated data.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 1.
Advanced Computing Data Bases: Basic concepts Based in part on open access material from: Database Management Systems by Raghu Ramakrishnan and Johannes.
1 CENG 351 CENG 351 Introduction to Data Management and File Structures Department of Computer Engineering METU.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Database Management Systems 1 Raghu Ramakrishnan The Relational Model Chapter 3 Instructor: Xin Zhang.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
 Database – collection of persistent data  Database Management System (DBMS) – software system that supports creation, population, and querying of a.
Introduction to DBMS Purpose of Database Systems View of Data
COP Introduction to Database Structures
CS 186, Fall 2006, Lecture 2 R & G, Chap. 3
Introduction to Database Systems
Overview of Database Systems Chpt 1
Introduction to Database Management System
Introduction to Database Systems
The Relational Model Relational Data Model
The Relational Model The slides for this text are organized into chapters. This lecture covers Chapter 3. Chapter 1: Introduction to Database Systems Chapter.
Database Management Systems CSE594
Introduction to DBMS Purpose of Database Systems View of Data
Introduction to Database Systems
Presentation transcript:

The Relational Model CS 186, Spring 2007, Lecture 2 Cow book Section 1.5, Chapter 3 Mary Roth

Administrivia Homework 0 –Due next Tuesday, Jan p.m. –Submission instructions added to homework description –Class account forms here if you need them Discussion sections will meet today Questions?

Outline What we learned last time –What is and what good is a DBMS anyway? –Components of a DBMS New stuff –A brief history of databases –The relational data model

Review: What is a database? A collection of data organized for rapid search and retrieval –Data collection has some logical meaning, and some reason for it to be organized in a particular way.

Review: What is a DBMS? A software system designed to manage a database. –Think big and lots of data 300,000,000 bank accounts –Think mission critical 1,000,000 transactions a day You’d need a DBMS to: –Help you find things fast –Help you keep track of what’s going on

Review: ACID properties A DBMS ensures a database has ACID properties: Atomicity – nothing is ever half baked; database changes either happen or they don’t. Consistency – you can’t peek at the data til it is baked; database changes aren’t visible til they are commited Isolation – concurrent operations have an explainable outcome; multiple users can operate on a database without conflicting Durability – what’s done is done; once a database operation completes, it remains even if the database crashes

Review: DBMS components A DBMS is like an ogre; it has layers –We’re going to learn about these layers all semester –We’re going to build several layers in our homework projects Query Optimization and Execution Relational Operators Files and Access Methods Buffer Management Disk Space Management DB

Review: DBMS components Query Optimization and Execution Relational Operators Access Methods Buffer Management Disk Space Management DB Makes efficient use of disk space -> Think 300,000,000 accounts! Makes efficient use of RAM -> Think 1,000,000 simultaneous requests! Provides generic ways to combine data -> Do you want a list of customers and accounts or the total account balance of all customers? Figures out the best way to answer a question -> There is always nore than 1 way to skin a cat…! Provides efficient ways to extract data -> Do you need 1 record or a bunch? Database application Talks to DBMS to manage data for a specific task -> e.g. app to withdraw/deposit money or provide a history of the account

Review: How does a DBMS work? Query Optimization and Execution Relational Operators Access Methods Buffer Management Disk Space Management Customer accounts stored on disk Query in: e.g. “Select min(account balance)” Data out: e.g Database app

Review: Typical architecture for DB applications DBMS Command lineGUI JDBC/ODBC app App server JDBC/ODBC Web browser 1. Enter queries, etc. By typing text 2. Graphically compose queries, look at data 3. Embed database access in a program 4. Embed database access in a web application

Summary: Benefits of a DBMS 1.Data independence –applications worry about what data they want, not how it is stored 2.Efficient data access –DBMS is smart about how to retrieve data 3.Data integrity and security –DBMS won’t let you corrupt data 4.Centralized administration –stored data on single server and let people specialize in managing it 5.Concurrent access –Handles multiple users efficiently and recoverably 6.Reduced application development time –Derived from 1-5

Minibase is a Java-based DBMS Query Optimization and Execution Relational Operators Access Methods Buffer Management Disk Space Management DB Provided for you Homework 1 Homework 4 Homework 3 (Pencil-work) Homework 2 Database application Homework 5

Intermission Get up and stretch Ask a quick question Get a drink of water

A brief history of databases Birth of the DBMS parallels adoption of computer over 1960s and 1970s 1960s: IBM introduced IMS –36 years old! –‘Legacy’ technology, but still important! 100,000,000 bank transactions a day move money through IMS system A bank manages over 300,000,000 online bank accounts on IMS One production IMS system has been running for over 8 years without down time or a crash

A brief history of databases 1970: Ted Codd introduced the relational data model –Revolutionary idea that spurred a flurry of DBMS activity –…at IBM (System R, DB2) –…at Universities like Berkeley (Ingres) –…at Oracle (it was born!!) Ted Codd won the Turing award in 1981 Larry Ellison became a gillionaire

So what’s the big deal about the relational data model? What is the first benefit of a DBMS? –Data independence A Data Model is key to data independence –It’s the link that provides an abstraction between user’s view of the world and bits stored in computer Student (sid: string, name: string, login: string, age: integer, gpa:real)

So what’s the big deal about the relational data model? It is now the most widely used data model. Before 1970, there were other data models… –Network –Hierarchical (IMS) But they didn’t really provide data independence –If the data layout changed, the application had to change –If you wanted to change the layout, you often had to bring the whole system down –Changes had to occur over scheduled system down time. Slow! Annoying! Expensive! The relational model changed all that.

Relational Database: Definitions Relational database: a set of relations. Relation: made up of 2 parts: –Schema : specifies name of relation, plus name and type of each column. e.g. Students(sid: string, name: string, login: string, age: integer, gpa: real) –Instance : a table, with rows and columns. #rows = cardinality #fields = degree / arity You can think of a relation as a set of rows or tuples. (It’s basically a spread sheet!) –i.e., all rows are distinct

Ex: Instance of Students Relation sid name login age gpa Jones Smith Smith Cardinality = 3, arity = 5, all rows distinct Do all values in each column of a relation instance have to be distinct?

SQL - A language for Relational DBs SQL (a.k.a. “Sequel”), standard language Data Definition Language (DDL) –create, modify, delete relations –specify constraints –administer users, security, etc. Data Manipulation Language (DML) –Specify queries to find tuples that satisfy criteria –add, modify, remove tuples

SQL Overview CREATE TABLE (, … ) INSERT INTO ( ) VALUES ( ) DELETE FROM WHERE UPDATE SET = WHERE SELECT FROM WHERE

Creating Relations in SQL Creates the Students relation. –Note: the type of each field is specified, and enforced by the DBMS whenever tuples are added or modified. CREATE TABLE Students (sid CHAR(20), name CHAR(20), login CHAR(10), age INTEGER, gpa FLOAT)

Table Creation (continued) Another example: the Enrolled table holds information about courses students take. CREATE TABLE Enrolled (sid CHAR(20), cid CHAR(20), grade CHAR(2))

Adding and Deleting Tuples Can insert a single tuple using: INSERT INTO Students (sid,name,login,age,gpa) VALUES Can delete all tuples satisfying some condition (e.g., name = Smith): DELETE FROM Students S WHERE S.name = ‘Smith’ Powerful variants of these commands are available; more later!

Keys Keys are a way to associate tuples in different relations sidnameloginagegpa sidcidgrade 53666Carnatic101C 53666Reggae203B 53650Topology112A 53666History105B Enrolled Students PRIMARY Key FOREIGN Key

Keys are the key to data independence! Big improvement over the hierarchical model –Relationships are determined by field value, not physical pointers!

Keys are the key to data independence! Let’s enroll Smith in EECS in CS186 –With hierarchical model CS186A IMS requires –A change to add a field for CS186 –A change to Smith’s record to have him point to the new field

Keys are the key to data independence! sidnameloginagegpa sidcidgrade 53666Carnatic101C 53666Reggae203B 53650Topology112A 53666History105B Enrolled Students 53688CS186A Let’s enroll Smith in EECS in CS186 –With relational model Relation model only requires –A data change to add a new row to Enrolled table

Let’s return to our bank… Can we apply a relational model to our bank spreadsheet?

Exercises to test your understanding… Write the DDL for our bank tables. –Include primary and foreign key definitions Write a SQL query (DML) that returns the names and account balances for all customers that have an account balance > Write a SQL query (DML) that withdraws $300 from Frodo’s account.