Information Systems Chapter 4 Relational Databases Modelling
Database design Modelling –Decide which part of reality is represented in a database –Agree on structure of the database before deciding on a particular implementation Conceptual Modelling –oriented towards application and users –independent of technology and implementation
Some Terminology Classes of similar objects (and their relationships) students Instances Student -name -firstname -birthdate -section -year Type (of table) Database Etudiant (relational) Schema Real world perceptionAbstraction / Description E/R Diagram Class
Conceptual Modelling Consider issues such as: –What entities to model –How entities are related –What constraints exist in the domain –How to achieve good designs
Database Design Formalisms 1. Entity/Relationship model (E/R): –More relational in nature. –Very widely used 2. Object Definition Language (ODL): –Closer in spirit to object-oriented models (e.g. Java) –Will not be covered Both can be translated (semi-automatically) to relational schemas
2. Entity / Relationship Diagrams Objects entities Classes entity sets Attributes. Relationships: - bidirectional Product Price Order
Company Name StockPrice Person ssn Name Adress Product Name Price Category makesemploysbays
Keys in E/R Diagrams Every entity set must have a key –a key is an attribute that has a different value for every entity Product Name Price Category
What is a Relation ? A mathematical definition: –if A, B are sets, then a relation R is a subset of A x B A={1,2,3}, B={a,b,c,d}, R = {(1,a), (1,c), (3,b)} - makes is a subset of Product x Company: a b c d A= B= Company Name StockPrice Product Name Price Category makes
Multiplicity of E/R Relations one-one: many-one many-many abcdabcd abcdabcd abcdabcd 11 N1 NN
Multiplicity of E/R Relations (2) (arrows notation) one-one: many-one many-many abcdabcd abcdabcd abcdabcd
Company Name StockPrice Person ssn Name Adress Product Name Price Category makesemploysbays N NN N 1 1 What does this say ? Person ssn Name Adress Product Name Price Category
Multi-way Relationships How do we model a purchase relationship between buyers, products and stores? Person ssn Name Adress Product Name Price Category purchase N Person ssn Name Adress Product Name Price Category Store Number Adress N N
Multiplicity in Multiway Relationships Q: what does the multiplicity 1 mean ? A: if I know the store, person, invoice, I know the movie too VideoStore Person Movie Invoice rental N N N 1
Multiplicity in Multiway Relationships Q: what do the multiplicities 1 mean ? A: store, person, invoice determines movie and store, invoice, movie determines person VideoStore Person Movie Invoice rental N N 1 1
Attributes on Relationships Person ssn Name Adress Product Name Price Category Purchase date N Person ssn Name Adress Product Name Price Category Store Number Adress N N
Converting Multi-way Relationships to Binary BuyerOf Product Name Price Category Product Name Price Category Store Number Adress N Person ssn Name Adress Person ssn Name Adress N Purchase Date ProductOf StoreOf N N N N
4. From E/R Diagrams to Relational Schema Entity set relation Relationship relation
Entity Set to Relation Product(name, category, price) name category price gizmo gadgets $19.99 Product Name Price Category
Relationships to Relations Makes(product-name, company-name, year) Product-name Product-Category Company-name year gizmo gadgets gizmoWorks 1963 (watch out for attribute name conflicts) Company Name StockPrice Product Name Price Category makes Year N N Product Name Price Category
Relationships to Relations No need for Makes. Modify Product: name category price companyName gizmo gadgets gizmoWorks Company Name StockPrice Product Name Price Category makes 1 N Product Name Price Category
Multi-way Relationships to Relations Person ssn Name Adress Product Name Price Category Purchase date N Person ssn Name Adress Product Name Price Category Store Number Adress N N Purchase(prodName,stName,ssn,date)
4. Design Principles What’s wrong? Product Person Country Moral: be faithful! Purchase President
Design Principles: What’s Wrong? Product Store President personName personAdress date Moral: pick the right kind of entities.
Product Person Store Dates date Moral: don’t complicate life more than it already is. Purchase
Modeling Subclasses Some objects in a class may be special define a new class better: define a subclass Products Software products Educational products So --- we define subclasses in E/R
Understanding Subclasses Think in terms of records: –Product –SoftwareProduct –EducationalProduct field1 field2 field1 field2 field1 field2 field3 field4 field5
Subclasses to Relations NamePriceCategory Gizmo99gadget Camera49photo Toy39gadget Nameplatforms Gizmounix NameAge Group Gizmotodler Toyretired Product Sw.Product Ed.Product
Modeling Subclass Structure
5. Constraints in E/R Diagrams Finding constraints is part of the modeling process. Commonly used constraints: Keys: social security number uniquely identifies a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Other constraints: peoples’ ages are between 0 and 150.
Keys in E/R Diagrams No formal way to specify multiple keys in E/R diagrams Underline: