An Aside: Matrices and Relations

Slides:



Advertisements
Similar presentations
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Advertisements

Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Conceptual Design using the Entity-Relationship Model
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
The Entity-Relationship Model
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 541: Database Systems S. Muthu Muthukrishnan. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.)  What are the entities.
The Entity-Relationship (ER) Model
The Entity-Relationship Model
Comp3300/fall021 The Entity-Relationship Model Chapter 2 What are the steps in designing a database ? Why is the ER model used to create an initial design?
The Entity-Relationship Model
The Entity-Relationship Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Conceptual Design and The Entity-Relationship Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.) –What are the entities.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Modeling Your Data Chapter 2. Overview of Database Design Conceptual design: –What are the entities and relationships in the enterprise? – What information.
The Entity-Relationship Model
Conceptual Design Using the Entity-Relationship (ER) Model
The Entity- Relationship Model CS 186 Fall 2002: Lecture 2 R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move.
The Entity-Relationship (ER) Model CS541 Computer Science Department Rutgers University.
The Entity- Relationship Model R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move forward or it dies. And I.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
ER continued, and ER to Relational Mappings R&G Chapters 2, 3 Lecture 22.
Modeling Your Data Chapter 2. Part II Discussion of the Model: Good Design/ Bad Design?
1 The Entity-Relationship Model Chapter 2. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design : (ER Model is used at this stage.)  What are the entities.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
1 Conceptual Design using the Entity- Relationship Model.
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
CSC 411/511: DBMS Design 1 1 Dr. Nan WangCSC411_L2_ER Model 1 The Entity-Relationship Model (Chapter 2)
ER & Relational: Digging Deeper R &G - Chapters 2 & 3.
Modeling Your Data Chapter 2 cs5421. Part II Discussion of the Model: Good Design/ Bad Design? cs5422.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
COP Introduction to Database Structures
Conceptual Design and The Entity-Relationship Model
The Entity-Relationship Model
CAS CS 460/660 Data Base Design Entity/Relationship Model
Logical DB Design: ER to Relational
The Entity-Relationship Model
Design Concepts & ER Model
MODELS OF DATABASE AND DATABASE DESIGN
These slides are based on the slides of your text book.
The Entity-Relationship Model
Modeling Your Data Chapter 2 cs542
The Entity-Relationship Model
Translation of ER-diagram into Relational Schema
Instructor: Elke Rundensteiner
From ER to Relational Model
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
Translation of ER-diagram into Relational Schema
The Entity-Relationship 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.
The Entity-Relationship Model
More on ER Model and the Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship (ER) Model
Presentation transcript:

An Aside: Matrices and Relations

How do we store a dense matrix? … a1,d a2,1 a2,2 a2,3 a2,d a3,1 a3,2 a3,3 a3,d a4,1 a4,2 a4,3 a4,d a5,1 a5,2 a5,3 a5,d an,1 an,2 an,3 an,d n The above is a “logical” model. Storing it (in RAM or disk) is a “physical” model.

How do we store a dense matrix? … a1,d a2,1 a2,2 a2,3 a2,d a3,1 a3,2 a3,3 a3,d a4,1 a4,2 a4,3 a4,d a5,1 a5,2 a5,3 a5,d an,1 an,2 an,3 an,d n a1,1a1,2 a1,3 … a1,d a2,1 a2,2 a2,3 … a2,d a3,1 a3,2 a3,3 … a3,d a4,1 a4,2 a4,3 … a4,d a5,1 a5,2 a5,3 … a5,d … an,1 an,2 an,3 … an,d n×d, row-major “linearization” of a matrix

How do we store a dense matrix? … a1,d a2,1 a2,2 a2,3 a2,d a3,1 a3,2 a3,3 a3,d a4,1 a4,2 a4,3 a4,d a5,1 a5,2 a5,3 a5,d an,1 an,2 an,3 an,d n a1,1 a2,1 a3,1 a4,1 a5,1 … an,1a1,2 a2,2 a3,2 a4,2 a5,2 … an,2a1,3 a2,3 a3,3 a4,3 a5,3 … an,3…a1,d a2,d a3,d a4,d a5,d … an,d n×d, column-major “linearization” of a matrix

How do we store a dense matrix? 1 2 3 4 n block-oriented linearization of the matrix (e.g. see ScaLAPACK’s block-cyclic linearization)

But what if it’s sparse? I.e. mostly 0 Store a set of triples: Common: one-hot and bag-of-words Store a set of triples: {(row, col, val)} I.e. a relation!

How do we store a sparse matrix? row column val 1 3 a1,3 7 a1,7 2 14 a2,14 2741 a2,2741 a3,14 116 a3,116 … store this on disk however you like to store relations… or use special encodings to enhance matrix arithmetic locality (see Wikipedia)

Tradeoffs (row,col) not stored Many possible layouts For disk storage For parallel partitioning Often tuned for matrix operations, e.g. multiplication Empty vals not stored Many possible layouts For disk storage For parallel partitioning Harder to tune for matrix operations Irregular structure Rows and columns can be arbitrary values Integers, reals, strings, etc.

Recall this slide Sparse Dense

Imagine Computing AB SELECT ____________, SUM(A.val*B.val) FROM A, B Sparse matrix stored as a relation: (row integer, col integer, value float) (AB)ij = 𝑘=1 𝑚 𝐴𝑖𝑘𝐵𝑘𝑗 SELECT ____________, SUM(A.val*B.val) FROM A, B WHERE ____________ GROUP BY ___________;

Imagine Computing AB SELECT ____________, SUM(A.val*B.val) FROM A, B Sparse matrix stored as a relation: (row integer, col integer, value float) (AB)ij = 𝑘=1 𝑚 𝐴𝑖𝑘𝐵𝑘𝑗 SELECT ____________, SUM(A.val*B.val) FROM A, B WHERE A.col = B.row GROUP BY ___________;

Imagine Computing AB SELECT A.row, B.col, SUM(A.val*B.val) FROM A, B Sparse matrix stored as a relation: (row integer, col integer, value float) (AB)ij = 𝑘=1 𝑚 𝐴𝑖𝑘𝐵𝑘𝑗 SELECT A.row, B.col, SUM(A.val*B.val) FROM A, B WHERE A.col = B.row GROUP BY A.row, B.col;

Imagine Computing AB Need to line up blocks: Dense matrix might be stored as a relation of blocks: (blockNum integer, subMatrix blob) Need to line up blocks: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 5 6 5 6 7 8 7 8 9 10 11 12 9 10 11 12

Imagine Computing AB Need to line up blocks: Dense matrix might be stored as a relation of blocks: (blockNum integer, subMatrix blob) Need to line up blocks: 1 2 3 4 1 2 3 5 6 7 8 4 5 6 7 8 9 10 11 12 9 10 11 12

Imagine Computing AB Need to line up blocks: Dense matrix might be stored as a relation of blocks: (blockNum integer, subMatrix blob) Need to line up blocks: 1 2 3 7 8 9 1 5 9 3 7 11 4 5 6 10 11 12 2 6 10 4 8 12

Imagine Computing AB SELECT SUM(local-matrix-multiply(A.subMatrix, Dense matrix might be stored as a relation of blocks: (blockNum integer, subMatrix blob) Need to line up blocks: SELECT SUM(local-matrix-multiply(A.subMatrix, B.subMatrix)) FROM A, B WHERE A.blocknum = arithmetic(B.blocknum); 1 2 3 7 8 9 1 5 9 3 7 11 4 5 6 10 11 12 2 6 10 4 8 12

Many other variants We looked at: Also Sparse relations Dense linearizations Dense blocking (relations of dense blocks) Also Relations of dense rows (row integer, vals blob) Relations of dense columns (col integer, vals blob) Compression schemes for sparse and dense From the Scientific Computing & DB literature And don’t forget non-numeric “dimensions”! At scale, looks pretty much like DB queries/dataflow! Even for dense matrice, across “blocks” Blocking may be or disk (out-of-core) or for parallelism

Quick Summary

Data Models R & G, Chaps. 2&3

Steps in Traditional Database Design Requirements Analysis user needs; what must database do? Conceptual Design high level description Logical Design translate into DBMS data model Schema Refinement consistency, normalization Physical Design indexes, disk layout Security Design who accesses what, and how

Describing Data: Data Models Data model : collection of concepts for describing data. Schema: description of a particular collection of data, using a given data model. 5

Two Data Models Linear Algebra Relational Model Main concept: matrix Matrix schema: dimensions n×d with indices from the ordinals domain for all “entries” Relational Model Main concept: relation (table), rows and columns Every relation has a schema describes the columns column names and simple domains Values in each column all match the domain

Relational Model Very expressive Yet very simple Can represent many data relationships Subsumes matrices, graphs, etc. Yet very simple Domains of columns are atomic types No nesting Expressive + Simple = Freedom Lots of room for database design

Why Focus on Relational Model? Most widely used model And many other models are subsets (e.g. key-value stores) Other models exist (and co-exist) “Legacy systems” in older models e.g., IBM’s IMS Object-Relational mergers Object-Oriented features provided by DBMS Object-Relational Mapping (ORM) outside the DBMS A la Rails (Ruby), Django (Python), Hibernate (Java) Documents: XML, JSON, etc. Nested or “semi-structured” data Languages like Xquery, XSLT, JSONic Many relational engines now handle these to a degree

Levels of Abstraction Users Views describe how users see the data. Conceptual schema defines logical structure Physical schema describes the files and indexes used. View 1 View 2 View 3 Conceptual Schema Physical Schema DB 6

Example: University Database Conceptual schema: Students(sid text, name text, login text, age integer, gpa float) Courses(cid text, cname text, credits integer) Enrolled(sid text, cid text, grade text) Physical schema: Relations stored as unordered files. Index on first column of Students. External Schema (View): Course_info(cid text, enrollment integer) 7

Data Models Connect concepts to bits! Many models exist We will ground ourselves in the Relational model Entity-Relationship model also handy for design Translates down to Relational Student (sid: string, name: string, login: string, age: integer, gpa:real) 1010111101

Which came first? Data or Model? Traditionally, the model first First, design conceptual schema Then load data. Recently, emphasis on data first First load bits Then impose schema lazily upon read ”Schema-on-Load” vs. “Schema-on-Read” Pros/Cons? Analogies to strong vs. loose typing in PL

Let’s look at both Schema-on-Load Data Independence An “engineered” design for your data Keep things “right”: enforce constraints Ensure shared understanding of data Ensure applications work well Data Independence Major theme of early relational databases

DB Design: Data Independence Insulate apps from structure of data I.e. model hides details of the bits! Logical data independence: Protection from changes in logical structure Physical data independence: Protection from changes in physical structure Q: Why particularly important for DBMS? Because databases and their associated applications persist.

Hellerstein’s Inequality Data independence matters when… Not just a database issue! E.g. consider elastic resources in the cloud. E.g. consider Internet-wide performance. …

Agile Analytics & “Schema on Use” 𝑑𝑎𝑝𝑝 𝑑𝑡 >> 𝑑𝑒𝑛𝑣 𝑑𝑡 What about agile, exploratory analytics? First, don’t let the lack of schema prevent storing data! Just vomit out binary, text, CSV, JSON, xlsx, etc. Shove into DBMS blobs or a filesystem (e.g. HDFS) Wrangle the data into shape as needed Essentially defining physio-logical views over the raw bits “Data Dependence” Each Analyst has their own “opinion” about the data “Opinion” embodied in custom code that is dependent on the bits! Fits well with data that is never (re)organized E.g. Big Data, logs, “data exhaust” Less of a fit with app-centric, update-heavy data

So Which is Better? It depends. On the use case Mission-critical? Exploratory? Stable? Fast-changing? On the environment Governance requirements? App developers? IT managers? Analysts? 𝑎𝑝𝑝 𝑒𝑛𝑣

Quick Summary

Entity-Relationship Diagrams R & G, Chaps. 2&3

Entity-Relationship Model Relational model is a great formalism and a clean system framework But a bit detailed for design time a bit fussy for brainstorming hard to communicate to customers Entity-Relationship model is a popular “shim” over relational model graphical, slightly higher level

Steps in Traditional Database Design Requirements Analysis user needs; what must database do? Conceptual Design high level description Logical Design translate into DBMS data model Schema Refinement consistency, normalization Physical Design indexes, disk layout Security Design who accesses what, and how

Conceptual Design What are the entities and relationships? What info about E’s & R’s should be in DB? What integrity constraints (business rules) hold? ER diagram is the “schema” Can map an ER diagram into a relational schema. This is where SW/data engineering begins Ruby-on-Rails “models” 2

ER Model Basics Entity: Entity Set: A collection of similar entities. Employees ssn name lot Entity: A real-world object described by a set of attribute values. Entity Set: A collection of similar entities. E.g., all employees. All entities in an entity set have the same attributes. Each entity set has a key (underlined) Each attribute has a domain The slides for this text are organized into several modules. Each lecture contains about enough material for a 1.25 hour class period. (The time estimate is very approximate--it will vary with the instructor, and lectures also differ in length; so use this as a rough guideline.) This covers Lectures 1 and 2 (of 6) in Module (5). Module (1): Introduction (DBMS, Relational Model) Module (2): Storage and File Organizations (Disks, Buffering, Indexes) Module (3): Database Concepts (Relational Queries, DDL/ICs, Views and Security) Module (4): Relational Implementation (Query Evaluation, Optimization) Module (5): Database Design (ER Model, Normalization, Physical Design, Tuning) Module (6): Transaction Processing (Concurrency Control, Recovery) Module (7): Advanced Topics 3

ER Model Basics (Contd.) since lot name Employees ssn dname budget did Departments Works_In Relationship: Association among two or more entities. E.g., Attishoo works in Pharmacy department. relationships can have their own attributes. Relationship Set: Collection of similar relationships. An n-ary relationship set R relates n entity sets E1 ... En ; each relationship in R involves entities e1 ∈E1, ..., en ∈En 4

ER Model Basics (Cont.) since Works_In dname budget did Departments lot name Employees ssn super-visor subor-dinate Reports_To Same entity set can participate in different relationship sets, or in different “roles” in the same relationship set. 4

Key Constraints An employee can work in many departments; a dept can have many employees. dname budget did Departments since Works_In lot name ssn Employees since Manages In contrast, each dept has at most one manager, according to the key constraint on Manages. 6

Participation Constraints Does every employee work in a department? If so: a participation constraint participation of Employees in Works_In is total (vs. partial) What if every department has an employee working in it? Participation: “at least one” since since name name dname dname ssn lot did did budget budget Employees Manages Departments Works_In since 8

Key & Participation Key: At most one lot name dname budget did since Manages Departments Employees ssn Works_In Key: At most one

Key & Participation Key: At most one Participation: At least one lot name dname budget did since Manages Departments Employees ssn Works_In Key: At most one Participation: At least one

Key & Participation Key: At most one Participation: At least one lot name dname budget did since Manages Departments Employees ssn Works_In Key: At most one Participation: At least one Both: ?

1-to-Many Many-to-1 since since name name dname dname ssn lot did did budget budget Employees Manages Departments 1-to-Many Many-to-1

Many-to-Many 1-to-Many Many-to-1 1-to-1

Alternative: Crow’s Foot Notation

Quick Summary

ER so far Entities and Entity Set (boxes) Relationships and Relationship sets (diamonds) Key constraints (arrows) Participation constraints (bold for Total) These are enough to get started, but we’ll need more…

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. lot name age pname Dependents Employees ssn Policy cost Weak entities have only a “partial key" (dashed underline) 10

Binary vs. Ternary Relationships name Employees ssn lot pname age Covers Dependents If each policy is owned by just 1 employee: Policies policyid cost Key constraint on Policies would mean policy can only cover 1 dependent! Beneficiary age pname Dependents policyid cost Policies Purchaser name Employees ssn lot Better design Think through all the constraints in the 2nd diagram! 7

Binary vs. Ternary Relationships (Contd.) Previous example: 2 binary relationships better than 1 ternary relationship. An example in the other direction: ternary relationship set Contracts relates entity sets Parts, Departments and Suppliers relationship set has descriptive attribute qty. no combo of binary relationships is a substitute! See next slide… 9

Binary vs. Ternary Relationships (Contd.) qty Parts Contract Departments VS. Suppliers Parts needs Departments can-supply Suppliers deals-with S “can-supply” P, D “needs” P, and D “deals-with” S does not imply that D has agreed to buy P from S. How do we record qty? 9

Aggregation Allows relationships with relationship sets. name ssn lot until Employees Monitors lot name ssn budget did pid started_on pbudget dname Departments Projects Sponsors since Allows relationships with relationship sets. 2

Aggregation vs. Ternary until Employees Monitors lot name ssn budget did pid started_on pbudget dname Departments Projects Sponsors since until Employees Monitors Sponsors lot name ssn budget did pid started_on pbudget dname Departments Projects since

Conceptual Design Using the ER Model ER modeling can get tricky! Design choices: Entity or attribute? Entity or relationship? Relationships: Binary or ternary? Aggregation? ER Model goals and limitations: Lots of semantics can (and should) be captured. Some constraints cannot be captured in ER. We’ll refine things in our logical (relational) design 3

Entity vs. Attribute “Address”: It depends! Semantics and usage. attribute of Employees? Entity of its own? It depends! Semantics and usage. Several addresses per employee? must be an entity atomic attribute types (no set-valued attributes!) Care about structure? (city, street, etc.) must be an entity! atomic attribute types (no tuple-valued attributes!)

Entity vs. Attribute (Cont.) from to name Employees ssn lot dname did Works_In2: employee cannot work in a department for >1 period. Like multiple addresses per employee! budget Works_In2 Departments name dname budget did ssn lot Employees Works_In3 Departments Duration from to 5

Entity vs. Relationship Separate discretionary budget (dbudget) for each dept. What if manager’s dbudget covers all managed depts Could repeat value But redundancy = problems Better design: since dbudget name dname ssn lot did budget Employees Manages2 Departments Employees since name dname budget did Departments ssn lot Mgr_Appts is_manager dbudget apptnum managed_by 6

E-R Diagram as Wallpaper Very common for them to be wall-sized

Converting ER to Relational Fairly analogous structure But many simple concepts in ER are subtle to specify in relations

Logical DB Design: ER to Relational ssn name lot Entity sets to tables. 123-22-3666 Attishoo 48 Employees ssn name lot 231-31-5368 Smiley 22 131-24-3650 Smethurst 35 CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn)) The slides for this text are organized into several modules. Each lecture contains about enough material for a 1.25 hour class period. (The time estimate is very approximate--it will vary with the instructor, and lectures also differ in length; so use this as a rough guideline.) This covers Lectures 1 and 2 (of 6) in Module (5). Module (1): Introduction (DBMS, Relational Model) Module (2): Storage and File Organizations (Disks, Buffering, Indexes) Module (3): Database Concepts (Relational Queries, DDL/ICs, Views and Security) Module (4): Relational Implementation (Query Evaluation, Optimization) Module (5): Database Design (ER Model, Normalization, Physical Design, Tuning) Module (6): Transaction Processing (Concurrency Control, Recovery) Module (7): Advanced Topics 3

Relationship Sets to Tables CREATE TABLE Works_In( ssn CHAR(1), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) In translating a many-to-many relationship set to a relation, attributes of the relation must include: 1) Keys for each participating entity set (as foreign keys). This set of attributes forms a superkey for the relation. 2) All descriptive attributes. ssn did since 123-22-3666 51 1/1/91 123-22-3666 56 3/3/93 231-31-5368 51 2/2/92 5

Review: Key Constraints Each dept has at most one manager, according to the key constraint on Manages. dname budget did since lot name ssn Manages Employees Departments Translation to relational model? 1-to-1 1-to Many Many-to-1 Many-to-Many 6

Translating ER with Key Constraints since Since each department has a unique manager, we could instead combine Manages and Departments. lot name ssn dname did budget Manages Employees Departments CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees) Vs. 7

Review: Participation Constraints Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every did value in Departments table must appear in a row of the Manages table (with a non-null ssn value!) since since name name dname dname ssn lot did did budget budget Employees Manages Departments Works_In since 8

Participation Constraints in SQL We can capture participation constraints involving one entity set in a binary relationship, but little else (without resorting to CHECK constraints). CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees ON DELETE NO ACTION) 9

Review: Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. name cost ssn pname lot age Employees Policy Dependents 10

Translating Weak Entity Sets Weak entity set and identifying relationship set are translated into a single table. When the owner entity is deleted, all owned weak entities must also be deleted. CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees ON DELETE CASCADE) 11

Quick Summary

Summary of Conceptual Design Conceptual design follows requirements analysis, Yields a high-level description of data to be stored You may want to postpone it for read-only “schema on use” ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Note: There are many variations on ER model Both graphically and conceptually Basic constructs: entities, relationships, and attributes (of entities and relationships). Some additional constructs: weak entities, ISA hierarchies (see text if you're curious), and aggregation. 11

Summary of ER (Cont.) Several kinds of integrity constraints: key constraints participation constraints Some foreign key constraints are also implicit in the definition of a relationship set. Many other constraints (notably, functional dependencies) cannot be expressed. Constraints play an important role in determining the best database design for an enterprise. 12

Summary of ER (Cont.) ER design is subjective. There are often many ways to model a given scenario! Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute, entity vs. relationship, binary or n-ary relationship, whether or not to use ISA hierarchies, aggregation. Ensuring good database design: resulting relational schema should be analyzed and refined further. Functional Dependency information and normalization techniques are especially useful. 13