Relational Databases (Part 2) Session 14 INST 301 Introduction to Information Science.

Slides:



Advertisements
Similar presentations
Relational Databases Week 9 INFM 603.
Advertisements

SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Computer Science & Engineering 2111 Introduction to Database Systems 1CSE 2111-Introduction to Database Systems.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
LBSC 690 Session #7 Structured Information: Databases Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under.
Accounting 6500 Relational Databases: Accounting Applications Introduction to Normalization.
Database Design and MySQL
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 1 Database Systems I Introduction.
RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE 
Databases Week 7 LBSC 690 Information Technology.
Week 6 LBSC 690 Information Technology
Databases Week 6 LBSC 690 Information Technology.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #13.
LBSC 690: Session 7 Relational Databases
MySQL and Requirements Session 4 INFM 718N Web-Enabled Databases.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Web-Database Integration
...Looking back Why use a DBMS? How to design a database? How to query a database? How does a DBMS work?
Relational Databases Week 7 LBSC 690 Information Technology.
Compe 301 ER - Model. Today DBMS Overview Data Modeling Going from conceptual requirements of a application to a concrete data model E/R Model.
LOGICAL DATABASE DESIGN
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Architecture The Relational Database Model.
Computer Science & Engineering 2111 Introduction to Database Management Systems Relationships and Database Creation 1 CSE 2111 Introduction to Database.
Database Systems Lecture 5 Natasha Alechina
Week 10 LBSC 671 Creating Information Infrastructures
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
Relational Databases Week 13 LBSC 671 Creating Information Infrastructures.
Relational Databases Week 9 INFM 603. Agenda Relational database design Microsoft Access MySQL Main Class Project Proposal Presentation.
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
Introduction. 
Chapters 17 & 18 Physical Database Design Methodology.
1 CSE 480: Database Systems Lecture 23: Transaction Processing and Database Recovery.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, March 5, 2014 Session 6: Relational.
Databases Session 5 LIS 7008 Information Technologies LSU/SLIS.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B.
CSC 2720 Building Web Applications Database and SQL.
Databases Week 5 LBSC 690 Information Technology.
CSCI 3140 Module 3 – Logical Database Design for the Relational Model Theodore Chiasson Dalhousie University.
1 IRU Concurrency, Reliability and Integrity issues Geoff Leese October 2007 updated August 2008, October 2009.
Relational Databases Week 11 LBSC 671 Creating Information Infrastructures.
Database Beginnings. Scenario so far In our scenario we have people registering for training sessions. –The data about the training sessions was placed.
Microsoft Access Intro Class 6 Relationships.
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.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Computer Science and Engineering Computer System Security CSE 5339/7339 Session 21 November 2, 2004.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Transaction Processing Concepts Muheet Ahmed Butt.
Relational Databases Week 7 INFM 603.
Fall CSE330/CIS550: Introduction to Database Management Systems Prof. Susan Davidson Office: 278 Moore Office hours: TTh
Data The fact and figures that can be recorded in system and that have some special meaning assigned to it. Eg- Data of a customer like name, telephone.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
Data Modeling Session 12 INST 301 Introduction to Information Science.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 1.
September 2000C.Watters1 Data & Database Management Systems (DBMS) ECMM6010.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Normalization.
Database Keys and Constraints
Translation of ER-diagram into Relational Schema
Teaching slides Chapter 8.
Lesson Objectives Aims You should know about: 1.3.2: (a) indexing (d) SQL – Interpret and Modify (e) Referential integrity (f) Transaction processing,
Microsoft Access and SQL
Week 6 LBSC 690 Information Technology
Presentation transcript:

Relational Databases (Part 2) Session 14 INST 301 Introduction to Information Science

“Project Team” E-R Example studentteam implement-role member-of project creates manage-role php-projectajax-project d 1 M M human client needs M1

Making Tables from E-R Diagrams Pick a primary key for each entity Build the tables –One per entity –Plus one per M:M relationship –Choose terse but memorable table and field names Check for parsimonious representation –Relational “normalization” –Redundant storage of computable values Implement using a DBMS

One Possible Table Structure Persons: id, fname, lname, userid, password Contacts: id, ctype, cstring Ctlabels: ctype, string Students: id, team, mrole Iroles: id, irole Rlabels: role, string Projects: team, client, pstring

CREATE TABLE persons ( id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, fname VARCHAR(15) NOT NULL, lname VARCHAR(30) NOT NULL, userid VARCHAR(40) NOT NULL, password VARCHAR(40) NOT NULL, PRIMARY KEY (id) ) ENGINE=INNODB; CREATE TABLE ctlabels ( ctype SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR(40) NOT NULL, PRIMARY KEY (ctype) ) ENGINE=INNODB; CREATE TABLE contacts ( ckey MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, id MEDIUMINT UNSIGNED NOT NULL, ctype SMALLINT UNSIGNED NOT NULL, cstring VARCHAR(40) NOT NULL, FOREIGN KEY (id) REFERENCES persons(id) ON DELETE CASCADE, FOREIGN KEY (ctype) REFERENCES ctlabels(ctype) ON DELETE RESTRICT, PRIMARY KEY (ckey) ) ENGINE=INNODB; CREATE TABLE rlabels ( role SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR(40) NOT NULL, PRIMARY KEY (role) ) ENGINE=INNODB; CREATE TABLE projects ( team SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, client MEDIUMINT UNSIGNED NOT NULL, string VARCHAR(40) NOT NULL, FOREIGN KEY (client) REFERENCES persons(id) ON DELETE RESTRICT, PRIMARY KEY (team) ) ENGINE=INNODB; CREATE TABLE students ( id MEDIUMINT UNSIGNED NOT NULL, team SMALLINT UNSIGNED, mrole SMALLINT UNSIGNED, FOREIGN KEY (id) REFERENCES persons(id) ON DELETE CASCADE, FOREIGN KEY (team) REFERENCES projects(team) ON DELETE SET NULL, FOREIGN KEY (mrole) REFERENCES rlabels(role) ON DELETE SET NULL, PRIMARY KEY (id) ) ENGINE=INNODB; CREATE TABLE iroles ( ikey MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, id MEDIUMINT UNSIGNED NOT NULL, irole SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (id) REFERENCES persons(id) ON DELETE CASCADE, FOREIGN KEY (irole) REFERENCES rlabels(role) ON DELETE CASCADE, PRIMARY KEY (ikey) ) ENGINE=INNODB; INSERT INTO rlabels (string) VALUES ('Project Manager'), ('System Architect'), ('Data Architect'), ('Test Designer'), ('PHP Programmer'), ('JavaScript Programmer'), ('Database Administrator'), ('XML Designer'); INSERT INTO ctlabels (string) VALUES ('primary '), ('alternate '), ('home phone'), ('cell phone'), ('work phone'), ('AOL IM'), ('Yahoo Chat'), ('MSN Messenger'), ('other'); INSERT INTO persons (fname, lname, userid, password) VALUES ('Sam', 'Cooper', 'coopers', SHA('pass')), ('Lindsey', 'Goshen', 'goshenl', SHA('pass')), ('Tommy', 'Teller', 'tellert', SHA('pass')), ('Nancy', 'Lange', 'langen', SHA('pass'));

RideFinder Exercise Design a database to match passengers with available rides for Spring Break Drivers phone in available seats –They want to know about interested passengers Passengers call up looking for rides –They want to know about available rides

Exercise Steps Create an E-R model –What entities? –What attributes? –What relations? Build the Tables –One per entity –Plus one per many-to-many relation Build the Queries –What happens when a passenger calls? –What happens when a driver calls?

Exercise Logistics Work in dissimilar teams of 2 Build an E-R model (10 minutes) –One team will present theirs to the class (5 min) Create the database (25 minutes) –Create tables –Put data in the tables –Create the queries One team will demo theirs to the class (5 min)

1NF: Single-valued indivisible (atomic) attributes –Split “Doug Oard” to two attributes as (“Doug”, “Oard”) –Model M:M implement-role relationship with a table 2NF: Attributes depend on complete primary key –(id, impl-role, name)->(id, name)+(id, impl-role) 3NF: Attributes depend directly on primary key –(id, addr, city, state, zip)->(id, addr, zip)+(zip, city, state) 4NF: Divide independent M:M tables –(id, role, courses) -> (id, role) + (id, courses) 5NF: Don’t enumerate derivable combinations

Database Integrity Registrar database must be internally consistent –Enrolled students must have an entry in student table –Courses must have a name What happens: –When a student withdraws from the university? –When a course is taken off the books?

Referential Integrity Foreign key values must exist in other table –If not, those records cannot be joined Can be enforced when data is added –Associate a primary key with each foreign key Helps avoid erroneous data –Only need to ensure data quality for primary keys

Concurrency Possible actions on a checking account –Deposit check (read balance, write new balance) –Cash check (read balance, write new balance) Scenario: –Current balance: $500 –You try to deposit a $50 check and someone tries to cash a $100 check at the same time –Possible sequences: (what happens in each case?) Deposit: read balance Deposit: write balance Cash: read balance Cash: write balance Deposit: read balance Cash: read balance Cash: write balance Deposit: write balance Deposit: read balance Cash: read balance Deposit: write balance Cash: write balance

Database Transactions Transaction: sequence of grouped database actions –e.g., transfer $500 from checking to savings “ACID” properties –Atomicity All-or-nothing –Consistency Each transaction must take the DB between consistent states. –Isolation: Concurrent transactions must appear to run in isolation –Durability Results of transactions must survive even if systems crash

Making Transactions Idea: keep a log (history) of all actions carried out while executing transactions –Before a change is made to the database, the corresponding log entry is forced to a safe location Recovering from a crash: –Effects of partially executed transactions are undone –Effects of committed transactions are redone the log

Key Ideas Databases are a good choice when you have –Lots of data –A problem that contains inherent relationships Join is the most important concept –Project and restrict just remove undesired stuff Design before you implement –Managing complexity is important