Databases : Lecture 11: Entity/Relationship modelling Timothy G. Griffin Lent Term

Similar documents
Databases : Lecture 11: Entity/Relationship modelling Timothy G. Griffin Lent Term

2. DatabaseDesign. Master I Software Engineering. Dr. Imed Bouchrika Dept of Mathematics & Computer Science University of Souk-Ahras

Databases : Lectures 11 and 12: Beyond ACID/Relational databases Timothy G. Griffin Lent Term 2013

Contents. Database. Information Policy. C03. Entity Relationship Model WKU-IP-C03 Database / Entity Relationship Model

Introduction to Database Design. Dr. Kanda Runapongsa Dept of Computer Engineering Khon Kaen University

High Level Database Models

Conceptual Design. The Entity-Relationship (ER) Model

Databases : Lecture 1 2: Beyond ACID/Relational databases Timothy G. Griffin Lent Term Apologies to Martin Fowler ( NoSQL Distilled )

Database Applications (15-415)

The Entity-Relationship Model

The Entity-Relationship Model. Overview of Database Design

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

OVERVIEW OF DATABASE DEVELOPMENT

CIS 330: Web-driven Web Applications. Lecture 2: Introduction to ER Modeling

The Entity-Relationship Model

Introduction to Database Design

The Entity-Relationship Model. Overview of Database Design. ER Model Basics. (Ramakrishnan&Gehrke, Chapter 2)

MIS Database Systems Entity-Relationship Model.

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Introduction to Database Design

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

Overview of db design Requirement analysis Data to be stored Applications to be built Operations (most frequent) subject to performance requirement

The Entity-Relationship Model

Introduction to Database Design

The Relational Model 2. Week 3

Conceptual Data Modeling

CSE 530A. ER Model. Washington University Fall 2013

The Entity-Relationship (ER) Model

COMP Instructor: Dimitris Papadias WWW page:

Introduction to Data Management. Lecture #2 (Big Picture, Cont.)

SYLLABUS ADMIN DATABASE SYSTEMS I WEEK 2 THE ENTITY-RELATIONSHIP MODEL. Assignment #2 changed. A2Q1 moved to A3Q1

High-Level Database Models (ii)

The Entity-Relationship (ER) Model 2

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

course 3 Levels of Database Design CSCI 403 Database Management Mines Courses ERD Attributes Entities title 9/26/2018

Introduction to Data Management. Lecture #2 (Big Picture, Cont.) Instructor: Chen Li

Review The Big Picture

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

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

From ER to Relational Model. Book Chapter 3 (part 2 )

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Database Applications (15-415)

The Entity-Relationship Model. Steps in Database Design

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

Introduction to Data Management. Lecture #3 (Conceptual DB Design) Instructor: Chen Li

Database Applications (15-415)

Chapter Outline. Note 1. Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Informatics 1: Data & Analysis

Chapter 2: Entity-Relationship Model

VARDHAMAN COLLEGE OF ENGINEERING Shamshabad , Hyderabad B.Tech. CSE IV Semester (VCE - R11) T P C 3+1* -- 4 (A1511) DATABASE MANAGEMENT SYSTEMS

MIT Database Management Systems Lesson 03: Entity Relationship Diagrams

CMPT 354 Database Systems I

CMSC 424 Database design Lecture 3: Entity-Relationship Model. Book: Chap. 1 and 6. Mihai Pop

Database Applications (15-415)

Overview. Introduction to Database Design. ER Model. Database Design

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

CSIT5300: Advanced Database Systems

Database Management Systems. Chapter 3 Part 2

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

The Relational Model. Chapter 3

Database Design. ER Model. Overview. Introduction to Database Design. UVic C SC 370. Database design can be divided in six major steps:

CS 146 Database Systems

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Data Modeling with the Entity Relationship Model. CS157A Chris Pollett Sept. 7, 2005.

Chapter 6: Entity-Relationship Model

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Chapter 13 XML: Extensible Markup Language

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

CS145 Introduction. About CS145 Relational Model, Schemas, SQL Semistructured Model, XML

A l Ain University Of Science and Technology

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

Full file at Chapter 2: Foundation Concepts

Using High-Level Conceptual Data Models for Database Design A Sample Database Application Entity Types, Entity Sets, Attributes, and Keys

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called


CSCI3030U Database Models

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints

Intro to DB CHAPTER 6

Modeling Your Data. Chapter 2. cs542 1

Database Design Process

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

A l Ain University Of Science and Technology

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

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

The Relational Model

The Relational Model (ii)

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007

DATA MODELS FOR SEMISTRUCTURED DATA

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

ER Model. Objectives (2/2) Electricite Du Laos (EDL) Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 1

Chapter 6: Entity-Relationship Model

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Entity Relationship Data Model. Slides by: Shree Jaswal

XGA XML Grammar for JAVA

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Conceptual Design. The Entity-Relationship (ER) Model

Transcription:

Databases : Lecture 11: Entity/Relationship modelling Timothy G. Griffin Lent Term 2010 Dr. Peter Chen http://bit.csc.lsu.edu/~chen/ www.cl.cam.ac.uk/teaching/current/databases/ 1 Conceptual Design What are the entities and relationships in the enterprise? What information about these entities and relationships should we store in the database? What are the integrity constraints (business rules) that hold? We can represent this information pictorially in E/R diagrams (and then map these to a relational schema later). 2

E/R basics An entity is a real-world object that is distinguishable from other objects Each entity has attributes (with domains) A particular entity will have a value for each of its attributes An entity type defines a set of entities that have the same attributes An entity set is the collection of all entities of a particular entity type (at a particular point in time) 3 Entities and attributes Entity types are drawn as rectangles, e.g. Attributes are drawn as ovals, and attached to the entity sets with lines, e.g. NI Name dob 4

Key attributes A key attribute of an entity type is an attribute whose values are distinct for each entity Sometimes several attributes (a composite attribute) together form a key NB: Such a composite should be minimal We underline key attributes NI Name dob 5 Entity types to relations A (strong) entity type maps to a relation schema in the obvious way, e.g. NI Name dob is mapped to the relation schema (NI:τ 1, Name:τ 2, dob:τ 3 ) 6

Relationships A relationship type among two or more entity types defines a set of associations between entities from those types Mathematically, relationship type R R E 1 E n. The set of instances of the relationship type is called the relationship set 7 Relationships in E/R Relationship types are represented by diamonds They connect the participating entity types with straight lines, e.g. NI Name dob DID dname budget Works_in Departments 8

Map to relation NI Name dob since DID dname budget M Works_in N Departments is mapped to the relation schema: Works_in(NI:τ 1, DID:τ 2, since:τ 3 ) 9 Relationship set diagrams Sometimes its useful to represent the relationship set diagrammatically e 1 e 2 e 3 e 4 e 5 r 1 r 2 r 3 r 4 d 1 d 2 d 3 d 4 d 5 10

Relationship attributes Relationships can also have attributes NB: A relationship must be uniquely determined by the entities, without reference to the relationship attributes NI Name dob since DID dname budget Works_in Departments 11 N-ary relationships Although relatively rare, we can have n-ary relationships, e.g. NI Name dob since DID dname budget Works_in2 Department address Locations capacity 12

Recursive relationships Each entity type in a relationship plays a particular role, which is associated with a role name (this is usually suppressed) An recursive relationship is when an entity type plays more than one role in the relationship type In this case the role name is required 13 Recursive relationships in E/R e.g. NI name dob supervisor subordinate Reports-to 14

Recursive relationship sets Just pick appropriate field names! E.g. NI name dob is mapped to supervisor Reports-to subordinate Reports_to(sup_NI:τ 1, sub_ni: τ 1 ) 15 Constraints on relationship types For example: An employee can work in many departments; a department can have many employees In contrast, each department has at most one manager Thus we need to be able to specify the number of relationship instances that an entity can participate in. For binary relationships the possible ratios are: 1:1, 1:N, N:1, M:N 16

Cardinality ratios 1:1 1:N M:N 17 Cardinality ratios in E/R M:N M N N:1 N 1 1:1 1 1 Note: Sometimes this is written using different arrowheads 18

Participation constraints Every department must have a manager This is an example of a participation constraint The participation of an entity set, E, in a relationship set R is said to be total if every entity in E participates in at least one relationship in R. (If not its participation is said to be partial) 19 Participation in E/R diagrams Total participation is displayed as a bold line between the entity type and the relationship NB. Sometimes this is written as a double line NI Name dob since DID dname budget 1 N Manages Department 20

Weak entity types An entity type may not have sufficient attributes to form a primary key Such an entity type is called a weak entity type A weak entity can only be identified uniquely by considering the primary key of another (owner) entity 21 Weak entity types cont. Thus the owner and weak entity types must participate in a 1:N relationship Weak entity set must have total participation in this identifying relationship set. NI Name Cost 1 N Policy pname Dependents age 22

Implementng Weak entity types Given a weak entity type, W, we generate a relation schema with fields consisting of the attributes of W, and the primary key attributes of the owner entity type For any relationship in which W appears we generate a relation schema which must take as the key for W all of its key attributes, including those from its owner set 23 Example NI Name Cost pname age 1 N Policy Dependents is mapped to the following schema: Dependents(pName:τ 1, NI:τ 2, age:τ 3 ) Policy(pName:τ 1, NI:τ 2, Cost:τ 4 ) Alternatively: Policy(pName :τ 1, NI :τ 2, age :τ 3, Cost :τ 4 ) 24

Extended E/R modelling What we ve seen so far is classic E/R Over the years a number of features have been added to the model and the modelling process These features include: Sub- and superclasses Specialisation Generalisation Categories Higher/Lower-level entity sets Attribute inheritance Aggregation 25 ISA hierarchies We can devise hierarchies for our entity types If we declare A ISA B, every A entity is considered to be a B entity rate NI hours Name ISA dob cid Temp_Emp Contract_Emp 26

ISA Hierarchies NI Name dob Two choices: 1. 3 relations rate hours ISA cid (, Temp_Emp and Contract_Emp) Temp_Emp Contract_Emp 2. 2 relations (Temp_Emp and Contract_Emp) 27 Databases Lecture 12: Database Systems Timothy G. Griffin Lent Term 2010 28

What is a database system? A database is a large, integrated collection of data A database contains a model of something! A database management system (DBMS) is a software system designed to store, manage and facilitate access to the database 29 What does a database system do? Manages Very Large Amounts of Data Supports efficient access to Very Large Amounts of Data Supports concurrent access to Very Large Amounts of Data Supports secure, atomic access to Very Large Amounts of Data 30

Database system architecture It is common to describe databases in two ways The logical level: What users see, the program or query language interface, The physical level: How files are organised, what indexing mechanisms are used, It is traditional to split the logical level into two: overall database design (conceptual) and the views that various users get to see A schema is a description of a database 31 Three-level architecture External Schema 1 External Schema 2 External Schema n Conceptual level Conceptual Schema External level Physical level Internal Schema 32

Logical and physical data independence Data independence is the ability to change the schema at one level of the database system without changing the schema at the next higher level Logical data independence is the capacity to change the conceptual schema without changing the user views Physical data independence is the capacity to change the internal schema without having to change the conceptual schema or user views 33 Database Context Database systems are more and more likely to support features that unlock databases and allow them to aasily interact in a larger context Data-warehousing features Data cube Inter-database exchange features XML 34

The Data Publishing Problem Need to share data without exposing internal details of your database. DB 5 DB 1 Exports.txt files in ad hoc format DB 4 Lack of standard exchange formats requires the implementation of many ad hoc translators Exports Excel DB 2 Exports.txt files in ad hoc format DB 2 Exports printed documents DB 3 Exports HTML Exports Word Documents 35 XML as a data exchange format DB 5 DB 1 Exports XML DB 2 Exports XML Exports XML XML conforming to agreed upon semantics DB 2 DB 4 Exports XML DB 3 Exports XML Exports XML 36

XML and Databases XML-enabled databases: Data stored in structured (usually relational) format. XML primarily used as a data exchange format Interfaces and SQL extensions provided to facilitate generation of XML and parsing of XML. Data-centric Native XML database: Allows direct storage and manipulation of XML data. Document-centric 37 What is XML? Extensible Markup Language W3C proposal, Current version 1.0 (3 rd ed.) February 2004 Authors: Tim Bray (Netscape) Jean Paoli (Microsoft) C.M. Sperberg-McQueen (W3C) Eve Maler (Sun) François Yergeau http://www.w3.org/tr/rec-xml XML has roots in HTML 38

HTML Lingua-franca for publishing hypertext on the web Designed to inform a web-browser both what information to render, and how it should be rendered (Actually these shouldn t be mixed up) Easy to learn (Big win) Fixed tag set, rather odd syntax 39 Opening tag Text (PCDATA) Closing tag Attribute (name and value) HTML: An example <HTML> <HEAD> <TITLE> Welcome to gmb s homepage </TITLE> </HEAD> <BODY> <H1>Background info</h1> <IMG SRC= me-and-britney.jpg > I have a lot of great friends </BODY> </HTML> 40

XML structure The fundamental construct is the element, which is essentially a pair of matching tags and the text between them, e.g. <name>britney</name> is an element <name>victoria</nom> is not an element XML documents must have single root element No fixed set of tags Elements can be properly nested, thus <name> <address> </address> </name> <name> <address> </name> </address> 41 XML structure cont. We can represent various structures using nesting and repetition Tuple (Record): <person> <name>emma Bunton</name> <tel>020 8777 1234</tel> <email>baby@spicegirls.com</email> </person> Lists: <addresses> <person> </person> <person> </person> <person> </person> </addresses> 42

XML structure cont. Nesting can be used to avoid joins, e.g. <bank> <cust><name>britney Spears</name> <address>florida</address> </cust> <acc> <accno>bs001</accno> <branch>florida High Street</branch> <balance>10,000,000</balance> </acc> <saver> <sname>britney Spears</sname> <saccno>bs001</saccno> </saver> </bank> 43 XML structure cont. Join avoiding: <bank2> <cust> <name>britney Spears</name> <address>florida</address> <acc> <accno>bs001</accno> <branch>florida High Street</branch> <balance>10,000,000</balance> </acc> </cust> </bank2> 44

XML and trees One can visualise XML documents as trees, e.g. person name tel email Emma Bunton 020 8777 1234 baby@spicegirls.com 45 Attributes In addition to elements we have attributes Attributes appear as name=value pairs in opening tags, e.g. <acc type= deposit > </acc> <acc type= saving status= closed > </acc> (Aside: An element with no body can be abbreviated from <foo></foo> to <foo/>) 46

DTDs XML documents can be created without any schema XML documents can contain a document type definition (DTD), which is similar to a schema 47 Example DTD <!DOCTYPE bank [ <!ELEMENT bank ((acc cust saver)+)> <!ELEMENT acc (accno branch balance)> <!ELEMENT cust (name address)> <!ELEMENT saver (sname saccno)> <!ELEMENT accno (#PCDATA)> <!ELEMENT branch (#PCDATA)> <!ELEMENT balance(#pcdata)> <!ELEMENT name (#PCDATA)> <!ELEMENT address(#pcdata)> <!ELEMENT sname (#PCDATA)> <!ELEMENT saccno (#PCDATA)> ]> 48

DTD details denotes alternative, + denotes one or more, and * denotes zero or more #PCDATA (Parsed Character Data) means any text! We can also specify attributes, e.g. <!ATTLIST acc acctype CDATA deposit > Element Attribute name Attribute Type (String of characters) Default value 49 Attributes An attribute of type ID provides a unique identifier for the element An attribute of type IDREF is a reference to an element Example: <!ATTLIST account number ID #REQUIRED owners IDREFS #REQUIRED> <account number= A001 owners= C001 C007 > </account> 50

Using DTDs DTDs are placed at the start of an XML document A document that conforms to its DTD is said to be valid Alternatively you can give a URL for a DTD, e.g. <!DOCTYPE mybank SYSTEM http://www.hsbc.com/mybank.dtd > <mybank> </mybank> 51 Aside on DTDs Wouldn t it be better in ML? datatype bank = BANK of bankitem list and bankitem = ACC of accno*branch*balance CUST of name*address SAVER of sname*saccno; type accno = string; type branch = string; type balance = string; (*could be int!*) type name = string; type address = string; type sname = string; type saccno = string; 52

Schema You ll have noticed weaknesses with DTDs from a database schema point of view Individual text elements and attributes can t be typed further We don t need ordered sub-elements in database world There is a lack of typing in IDs and IDREFs An effort to address these problems has led to a better schema language: XML schema 53 Domain specific DTDs There are now lots of DTDs that have been agreed by groups, including WML: Wireless markup language (WAP) OFX: Open financial exchange CML: Chemical markup language AML: Astronomical markup language MathML: Mathematics markup language SMIL: Synchronised Multimedia Integration Language ThML: Theological markup language 54

Native XML Databases shred publish <?xml version="1.0" encoding="iso-8859-1"?> <nitf> <head> <title>colombia Earthquake</title> </head> <body> <body.head> <headline> <hl1>143 Dead in Colombia Earthquake</hl1> </headline> <byline> <bytag>by Jared Kotler, Associated Press Writer</bytag> </byline> <dateline> <location>bogota, Colombia</location> <story.date>monday January 25 1999 7:28 ET</story.date> </dateline> </body.head> </body> </nitf> <?xml version="1.0" encoding="iso-8859-1"?> <n itf> <head> <title>colombia Earthquake</title> </head> <body> <b ody.head> <headline> <hl1>143 Dead in Colombia Earthquake</hl1> </headline> <byline> <b ytag>by Jared Kotler, Associated Press Writer</bytag> </byline> <dateline> <location>bogota, Colombia</location> <story.date>monday January 25 1999 7:28 ET</s tory.date> </dateline> </body.head> </body> </nitf> XML-enabled Native XML 55 Documents vs databases But this is a document, which is quite different from our world of databases Document world Lots of small documents Static (normally) Implicit structure Tagging Human friendly Meta data: Author, title, date Editing Retrieval (IR) Database world A few large databases Dynamic Explicit structure (schema) Records Machine friendly Meta data: schema Updating Querying 56