CMSC424: Database Design Instructor: Amol Deshpande

Slides:



Advertisements
Similar presentations
Text-Book Chapters (7 and 8) Entity-Relationship Model
Advertisements

CMSC424, Spring 2005 CMSC424: Database Design Instructor: Amol Deshpande
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
Databases Revision.
Database Management System (DBMS)
CMSC424: Database Design Instructor: Amol Deshpande
On Database Systems.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
CMSC724: Database Management Systems Instructor: Amol Deshpande
CMSC424: Review. Database Management Systems Manage data ► Store data ► Update data ► Answer questions about the data.
1–1 The E-R Model Prof. Sin-Min Lee Department of Computer Science.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Database Management Systems Purpose of Database Systems View of Data.
CMSC424, Spring 2005 CMSC424: Database Design Instructor: Amol Deshpande
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Entity-Relationship Model Database Management Systems I Alex Coman, Winter.
CMSC424: Database Design Instructor: Amol Deshpande
Modeling & Designing the Database
Compe 301 ER - Model. Today DBMS Overview Data Modeling Going from conceptual requirements of a application to a concrete data model E/R Model.
Dr. Kalpakis CMSC 461, Database Management Systems Introduction.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Entity-Relationship Model
Introduction to DBMS Purpose of Database Systems View of Data
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
ADVANCED DATABASES WITH ORACLE 11g FOR ADDB7311 LEARNING UNIT 1 of 7.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-02,03 Introduction –Data Models Lectured by, Jesmin Akhter.
Introduction to Databases
Introduction. 
Entity-Relationship Model
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T5 DESIGNING DATABASE APPLICATIONS.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
1 Chapter 1 Introduction. 2 Introduction n Definition A database management system (DBMS) is a general-purpose software system that facilitates the process.
CMSC424: Database Design Instructor: Amol Deshpande
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
Databases Shortfalls of file management systems Structure of a database Database administration Database Management system Hierarchical Databases Network.
Entity-Relationship Model Using High-Level Conceptual Data Models for Database Design Entity Types, Sets, Attributes and Keys Relationship Types, Sets,
DeSiamorePowered by DeSiaMore1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Computing & Information Sciences Kansas State University Wednesday, 24 Sep 2008CIS 560: Database System Concepts Lecture 12 of 42 Wednesday, 24 September.
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
 Entity-relationship models (ERM) Entity-relationship models (ERM)  Simple E-R Diagram Simple E-R Diagram  Weak Entity Weak Entity  Strong Entity.
1 CS3431 – Database Systems I Introduction Instructor: Mohamed Eltabakh
ITTelkom Entity Relationship Diagram (1) CS2343 Perancangan Basisdata Relasional.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
Databases Illuminated Chapter 3 The Entity Relationship Model.
Database and Information Retrieval System
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 1: Introduction
Logical Database Design and the Relational Model.
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Lecture 26 Enterprise Systems Development ( CSC447 ) COMSATS Islamabad Muhammad Usman, Assistant Professor.
CS3431: C-Term CS3431 – Database Systems I Introduction Instructor: Mohamed Eltabakh
Lecture on Database Management System
Database System Concepts Introduction Purpose of Database Systems View of Data Data Models Data Definition Language Data Manipulation Language Transaction.
©Silberschatz, Korth and Sudarshan 1.1 Database System Concepts قواعد البيانات Data Base قواعد البيانات CCS 402 Mr. Nedal hayajneh E- mail
CHAPTER 1: INTRODUCTION Purpose of Database Systems View of Data Data Models Data Definition Language Data Manipulation Language Storage Management Database.
Entity Relationship Model
Entity-Relationship Model
Databases and Database Management Systems Chapter 9
Introduction to Database Systems
Chapter 6: Entity-Relationship Model
Data Models in DBMS A model is a representation of reality, 'real world' objects and events, associations. Data Model can be defined as an integrated collection.
Syllabus Study Introduction to database Relational algebra
Presentation transcript:

CMSC424: Database Design Instructor: Amol Deshpande

Today DBMS Overview Data Modeling Going from conceptual requirements of a application to a concrete data model E/R Model

Example Simple Banking Application Need to store information about: Accounts Customers Need to support: ATM transactions Queries about the data Why we can’t use a file-system based solution ?

A file-system based solution Data stored in files in ASCII format #-seperated files in /usr/db directory /usr/db/accounts Account Number # Balance 101 # # 700 … /usr/db/customers Customer Name # Customer Address # Account Number Johnson # 101 University Blvd # 101 Smith # 1300 K St # 102 Johnson # 101 University Blvd # 103 …

A file-system based solution Write application programs to support the operations In your favorite programming language To support withdrawals by a customer for amount $X from account Y Scan /usr/db/accounts, and look for Y in the 1 st field Subtract $X from the 2 nd field, and rewrite the file To support finding names of all customers on street Z Scan /usr/db/customers, and look for (partial) matches for Z in the addess field …

What’s wrong with this solution ? Hard to control redundancy Hard to evolve the structure Data retrieval requires writing application programs Semantic constraints all over the place Not fast enough ! Data consistency issues Disk crashes etc Security Database management provide an end-to-end solution to all of these problems

How ? The key insight is whats called data abstraction

Data Abstraction Probably the most important purpose of a DBMS Goal: Hiding low-level details from the users of the system Through use of logical abstractions

Data Abstraction Logical Level Physical Level View Level View 1View 2View n … How data is actually stored ? e.g. are we using disks ? Which file system ? What data is stored ? describe data properties such as data semantics, data relationships What data users and application programs see ?

Data Abstraction: Banking Example Logical level: Provide an abstraction of tables Two tables can be accessed: accounts  Columns: account number, balance customers  Columns: name, address, account number View level: A teller (non-manager) can only see a part of the accounts table Not containing high balance accounts

Data Abstraction: Banking Example Physical Level: Each table is stored in a separate ASCII file # separated fields Identical to what we had before ? BUT the users are not aware of this They only see the tables The application programs are written over the tables abstraction Can change the physical level without affecting users In fact, can even change the logical level without affecting the teller

DBMS at a Glance 1. Data Modeling 2. Data Retrieval 3. Data Storage 4. Data Integrity

Data Modeling A data model is a collection of concepts for describing data properties and domain knowledge: Data relationships Data semantics Data constraints We will discuss two models extensively in this class Entity-relationship Model Relational Model Probably discuss XML as well

Data Retrieval Query = Declarative data retrieval program describes what data to acquire, not how to acquire it Non-declarative: scan the accounts file look for number 55 in the 2 nd field subtract $50 from the 3 rd field Declarative (posed against the tables abstraction): Subtract $50 from the column named balance for the row corresponding to account number 55 in the accounts table How to do it is not specified. Why ? Easier to write More efficient to execute (why ?)

Data Storage Where and how to store data ? Main memory ? What if the database larger than memory size ? Disks ? How to move data between memory and disk ? Etc etc…

Data Integrity Manage concurrency and crashes Transaction: A sequence of database actions enclosed within special tags Properties: Atomicity: Entire transaction or nothing Consistency: Transaction, executed completely, take database from one consistent state to another Isolation: Concurrent transactions appear to run in isolation Durability: Effects of committed transactions are not lost Consistency: Transaction programmer needs to guarantee that DBMS can do a few things, e.g., enforce constraints on the data Rest: DBMS guarantees

Data Integrity Semantic constraints Typically specified at the logical level E.g. balance > 0

DBMS at a glance Data Models Conceptual representation of the data Data Retrieval How to ask questions of the database How to answer those questions Data Storage How/where to store data, how to access it Data Integrity Manage crashes, concurrency Manage semantic inconsistencies Not fully disjoint categorization !!

Recap Data Models Conceptual representation of the data Data Retrieval How to ask questions of the database How to answer those questions Data Storage How/where to store data, how to access it Data Integrity Manage crashes, concurrency Manage semantic inconsistencies

Data Modeling Goals: Conceptual representation of the data “Reality” meets “bits and bytes” Must make sense, and be usable by other people We will study: Entity-relationship Model Relational Model Note the difference !! May study XML-based models or object-oriented models Why so many models ??

Motivation You’ve just been hired by Bank of America as their DBA for their online banking web site. You are asked to create a database that monitors: customers accounts loans branches transactions, … Now what??!!!

22 Database Design Steps Three Levels of Modeling info Conceptual Data Model Logical Data Model Physical Data Model Conceptual DB design Logical DB design Physical DB design Entity-relationship Model Typically used for conceptual database design Relational Model Typically used for logical database design

Entity-Relationship Model Two key concepts Entities: An object that exists and is distinguishable from other objects  Examples: Bob Smith, BofA, CMSC424 Have attributes (people have names and addresses) Form entity sets with other entities of the same type that share the same properties  Set of all people, set of all classes Entity sets may overlap  Customers and Employees

Entity-Relationship Model Two key concepts Relationships: Relate 2 or more entities  E.g. Bob Smith has account at College Park Branch Form relationship sets with other relationships of the same type that share the same properties  Customers have accounts at Branches Can have attributes:  has account at may have an attribute start-date Can involve more than 2 entities  Employee works at Branch at Job

25 ER Diagram: Starting Example Rectangles: entity sets Diamonds: relationship sets Ellipses: attributes customer has cust-street cust-id cust-name cust-city account balance number access-date

Rest of the class Details of the ER Model How to represent various types of constraints/semantic information etc. Design issues A detailed example

Next: Relationship Cardinalities We may know: One customer can only open one account OR One customer can open multiple accounts Representing this is important Why ? Better manipulation of data If former, can store the account info in the customer table Can enforce such a constraint Application logic will have to do it; NOT GOOD Remember: If not represented in conceptual model, the domain knowledge may be lost

Mapping Cardinalities Express the number of entities to which another entity can be associated via a relationship set Most useful in describing binary relationship sets

Mapping Cardinalities One-to-One One-to-Many Many-to-One Many-to-Many customer has account customer has account customer has account customer has account

Mapping Cardinalities Express the number of entities to which another entity can be associated via a relationship set Most useful in describing binary relationship sets N-ary relationships ? More complicated Details in the book

Next: Types of Attributes Simple vs Composite Single value per attribute ? Single-valued vs Multi-valued E.g. Phone numbers are multi-valued Derived If date-of-birth is present, age can be derived Can help in avoiding redundancy, enforcing constraints etc…

Types of Attributes customer has cust-street cust-id cust-name cust-city account balance number access-date

Types of Attributes customer cust-street cust-id cust-name cust-city has account balance number access-date phone no. date-of-birth age month dayyear Composite Attribute

Next: Keys Key = set of attributes that uniquely identifies an entity or a relationship

customer cust-street cust-id cust-name cust-city phone no. age date-of-birth Possible Keys: {cust-id} {cust-name, cust-city, cust-street} {cust-id, age} cust-name ?? Probably not. Domain knowledge dependent !! Entity Keys

Superkey any attribute set that can distinguish entities Candidate key a minimal superkey Can’t remove any attribute and preserve key-ness  {cust-id, age} not a candidate key  {cust-name, cust-city, cust-street} is  assuming cust-name is not unique Primary key Candidate key chosen as the key by DBA Underlined in the ER Diagram

Entity Keys {cust-id} is a natural primary key Typically, SSN forms a good primary key Try to use a candidate key that rarely changes e.g. something involving address not a great idea customer cust-street cust-id cust-name cust-city phone no. age date-of-birth

Relationship Set Keys What attributes are needed to represent a relationship completely and uniquely ? Union of primary keys of the entities involved, and relationship attributes {cust-id, access-date, account number} describes a relationship completely customer has cust-id account number access-date

Relationship Set Keys Is {cust-id, access-date, account number} a candidate key ? No. Attribute access-date can be removed from this set without losing key-ness In fact, union of primary keys of associated entities is always a superkey customer has cust-id account number access-date

Relationship Set Keys Is {cust-id, account-number} a candidate key ? Depends customer has cust-id account number access-date

Relationship Set Keys Is {cust-id, account-number} a candidate key ? Depends customer has cust-id account number access-date If one-to-one relationship, either {cust-id} or {account-number} sufficient Since a given customer can only have one account, she can only participate in one relationship Ditto account

Relationship Set Keys Is {cust-id, account-number} a candidate key ? Depends customer has cust-id account number access-date If one-to-many relationship (as shown), {account-number} is a candidate key A given customer can have many accounts, but at most one account holder per account allowed

Relationship Set Keys General rule for binary relationships one-to-one: primary key of either entity set one-to-many: primary key of the entity set on the many side many-to-many: union of primary keys of the associate entity sets n-ary relationships More complicated rules

… What have we been doing Why ? Understanding this is important Rest are details !! That’s what books/manuals are for.