Database Design Object Oriented Modeling Logical Design and
Database Design: Object. Oriented Modeling, Logical Design and Normalization University of California, Berkeley School of Information Management and Systems SIMS 202: Information Organization and Retrieval 9/20/2000 Information Organization and Retrieval
Review • New Personal Database assignment • Database Design Process • Basics of ER Diagrams 9/20/2000 Information Organization and Retrieval
Dive. Shop ER Diagram Customer No Dive. Cust 1 Destination Name Destination no Customer No 1 n Destination no Site No 1 Site No Species No n Bio. Site Ship. Via n Dive. Ords Destination n Order No n 1 1/n 9/20/2000 Dive. Item Ship. Wrck n Ship. Via Site No 1 Order No Item No n 1 Species No 1 1 1 Sites n Dive. Stok Bio. Life Information Organization and Retrieval Item No Ship. Via
Today • Object Oriented Modeling and UML • Logical Database Design • Normalization • (Most UML examples based on Mc. Fadden, “Modern Database Management”, 5 th edition. 9/20/2000 Information Organization and Retrieval
Object-Oriented Modeling • Becoming increasingly important as – Object-Oriented and Object-Relational DBMS continue to proliferate – Databases become more complex and have more complex relationships than are easily captured in ER or EER diagrams 9/20/2000 Information Organization and Retrieval
Object Benefits • Encapsulate both data and behavior • Object-oriented modeling methods can be used for both database design and process design – Real-World applications have more than just the data in the database they also involve the processes, calculations, etc performed on that data to get real tasks done – OOM can be used for more challenging and complex problems 9/20/2000 Information Organization and Retrieval
Unified Modeling Language (UML) • Combined three competing methods • Can be used for graphically depicting – Software designs and interaction – Database – Processes • 9/20/2000 Information Organization and Retrieval
CLASS • A class is a named description of a set of objects that share the same attributes, operations, relationships, and semantics. – An object is an instance of a class that encapsulates state and behavior. • These objects can represent real-world things or conceptual things. – An attribute is a named property of a class that describes a range of values that instances of that class might hold. – An operation is a named specification of a service that can be requested from any of a class's objects to affect behavior in some way or to return a value without affecting behavior 9/20/2000 Information Organization and Retrieval
UML Relationships • An relationship is a connection between or among model elements. • The UML defines four basic kinds of relationships: – Association – Dependency – Generalization – Realization 9/20/2000 Information Organization and Retrieval
UML Diagrams • The UML defines nine types of diagrams: – activity diagram – class diagram • Describes the data and some behavioral (operations) of a system – – – – 9/20/2000 collaboration diagram component diagram deployment diagram object diagram sequence diagram statechart diagram use case diagram Information Organization and Retrieval
Class Diagrams • A class diagram is a diagram that shows a set of classes, interfaces, and/or collaborations and the relationships among these elements. 9/20/2000 Information Organization and Retrieval
UML Class Diagram DIVEORDS Order No Customer No Sale Date Shipvia Payment. Method CCNumber No of People Depart Date Return Date Destination Vacation Cost Class Name List of Attributes Calc. Total. Invoice() Calc. Equipment() 9/20/2000 Information Organization and Retrieval List of operations
Object Diagrams 307: DIVORDS Order No = 307 Customer No = 1480 Sale Date = 9/1/99 Ship Via = UPS Payment. Method = Visa CCNumber = 12345 678 90 CCExp. Date = 1/1/01 No of People = 2 Depart Date = 11/8/00 Return Date = 11/15/00 Destination = Fiji Vacation Cost = 10000 9/20/2000 Information Organization and Retrieval
Differences from Entities in ER • Entities can be represented by Class diagrams • But Classes of objects also have additional operations associated with them 9/20/2000 Information Organization and Retrieval
Operations • Three basic types for database – Constructor – Query – Update 9/20/2000 Information Organization and Retrieval
Associations • An association is a relationship that describes a set of links between or among objects. • An association can have a name that describes the nature of this relationship. You can put a triangle next to this name to indicate the direction in which the name should be read. • An association contains an ordered list of association ends. – An association with exactly two association ends is called a binary association – An association with more than two ends is called an nary association. 9/20/2000 Information Organization and Retrieval
Associations: Unary relationships * 0. . 1 Person Is-married-to 0. . 1 manager 0. . 1 9/20/2000 Employee Information Organization and Retrieval manages
Associations: Binary Relationship Employee 0. . 1 Is-assigned Parking Place 0. . 1 One-to-one Product Line 1 contains * Product One-to-many Student * Registers-for Many-to-many 9/20/2000 Information Organization and Retrieval * Course
Associations: Ternary Relationships Part * Vendor 9/20/2000 * Supplies Information Organization and Retrieval * Warehouse
Association Classes Registers-for Student * Course * Computer Account Registration _________ acct. ID Term issues Password * 0. . 1 Grade Server. Space ________ Check. Eligibility() 9/20/2000 Information Organization and Retrieval
Derived Attributes, Associations, and Roles Course Student Course Offering ____________ Scheduled-for name Registers-for crse. Code term ssn * crse. Title * * 1 section date. Of. Birth credit. Hrs time Derived /age location attribute * * /participant Derived role {age = current. Date – date. Of. Birth} /Takes Derived association 9/20/2000 Information Organization and Retrieval
Generalization Employee ______ emp. Name emp. Number address date. Hired ______ print. Label() Hourly Employee ________ Hourly. Rate ________ compute. Wages() 9/20/2000 Salaried Employee ________ Annual Sal stockoption ________ Information Organization and Retrieval Contributepension() Consultant ________ contract. Number billing. Rate ________ compute. Fees()
Other Diagramming methods • SOM (Semantic Object Model) • Object Definition Language (ODL) – Not really diagramming – See Text chapter 3 • Access relationships display • Hybrids 9/20/2000 Information Organization and Retrieval
Application of SOM to Diveshop DIVECUST Name Address Street City State. Province ZIPPostal. Code Country Phone First. Contact 1. 1 1. 1 DIVEORDS 9/20/2000 1. N Information Organization and Retrieval 1. 1
DIVEORDS Order. No Sale. Date DIVECUST id SHIPVIA DESTINATION DIVEITEM Payment. Method CCNumber CCExp. Date No. Of. People Depart. Date Return. Date Vacation. Cost 9/20/2000 Information Organization and Retrieval
Dive. Shop ER Diagram Customer No Dive. Cust 1 Destination Name Destination no Customer No 1 n Destination no Site No 1 Site No Species No n Bio. Site Ship. Via n Dive. Ords Destination n Order No n 1 1/n 9/20/2000 Dive. Item Ship. Wrck n Ship. Via Site No 1 Order No Item No n 1 Species No 1 1 1 Sites n Dive. Stok Bio. Life Information Organization and Retrieval Item No Ship. Via
Entities • • • Customer Dive Order Line item Shipping information Dive Equipment Stock/Inventory • Dive Locations 9/20/2000 • Dive Sites • Sea Life • Shipwrecks Information Organization and Retrieval
Logical Design: Mapping to a Relational Model • Each entity in the ER Diagram becomes a relation. • A properly normalized ER diagram will indicate where intersection relations for many-to-many mappings are needed. • Relationships are indicated by common columns (or domains) in tables that are related. • We will examine the tables for the Diveshop derived from the ER diagram 9/20/2000 Information Organization and Retrieval
Customer = DIVECUST 9/20/2000 Information Organization and Retrieval
Dive Order = DIVEORDS 9/20/2000 Information Organization and Retrieval
Line item = DIVEITEM 9/20/2000 Information Organization and Retrieval
Shipping information = SHIPVIA 9/20/2000 Information Organization and Retrieval
Dive Equipment Stock/Inventory = DIVESTOK 9/20/2000 Information Organization and Retrieval
Dive Locations = DEST 9/20/2000 Information Organization and Retrieval
Dive Sites = SITE 9/20/2000 Information Organization and Retrieval
Sea Life = BIOLIFE 9/20/2000 Information Organization and Retrieval
BIOSITE -- linking relation 9/20/2000 Information Organization and Retrieval
Shipwrecks = SHIPWRK 9/20/2000 Information Organization and Retrieval
Normalization • Normalization theory is based on the observation that relations with certain properties are more effective in inserting, updating and deleting data than other sets of relations containing the same data • Normalization is a multi-step process beginning with an “unnormalized” relation – Hospital example from Atre, S. Data Base: Structured Techniques for Design, Performance, and Management. 9/20/2000 Information Organization and Retrieval
Normal Forms • • • First Normal Form (1 NF) Second Normal Form (2 NF) Third Normal Form (3 NF) Boyce-Codd Normal Form (BCNF) Fourth Normal Form (4 NF) Fifth Normal Form (5 NF) 9/20/2000 Information Organization and Retrieval
Normalization No transitive dependency between nonkey attributes All determinants are candidate keys - Single multivalued dependency 9/20/2000 Boyce. Codd and Higher Information Organization and Retrieval Functional dependencyof nonkey attributes on the primary key - Atomic values only Full Functional dependencyof nonkey attributes on the primary key
Unnormalized Relations • First step in normalization is to convert the data into a two-dimensional table • In unnormalized relations data can repeat within a column 9/20/2000 Information Organization and Retrieval
Unnormalized Relation 9/20/2000 Information Organization and Retrieval
First Normal Form • To move to First Normal Form a relation must contain only atomic values at each row and column. – No repeating groups – A column or set of columns is called a Candidate Key when its values can uniquely identify the row in the relation. 9/20/2000 Information Organization and Retrieval
First Normal Form 9/20/2000 Information Organization and Retrieval
1 NF Storage Anomalies • Insertion: A new patient has not yet undergone surgery -- hence no surgeon # -- Since surgeon # is part of the key we can’t insert. • Insertion: If a surgeon is newly hired and hasn’t operated yet -- there will be no way to include that person in the database. • Update: If a patient comes in for a new procedure, and has moved, we need to change multiple address entries. • Deletion (type 1): Deleting a patient record may also delete all info about a surgeon. • Deletion (type 2): When there are functional dependencies (like side effects and drug) changing one item eliminates other information. 9/20/2000 Information Organization and Retrieval
Second Normal Form • A relation is said to be in Second Normal Form when every nonkey attribute is fully functionally dependent on the primary key. – That is, every nonkey attribute needs the full primary key for unique identification 9/20/2000 Information Organization and Retrieval
Second Normal Form 9/20/2000 Information Organization and Retrieval
Second Normal Form 9/20/2000 Information Organization and Retrieval
Second Normal Form 9/20/2000 Information Organization and Retrieval
1 NF Storage Anomalies Removed • Insertion: Can now enter new patients without surgery. • Insertion: Can now enter Surgeons who haven’t operated. • Deletion (type 1): If Charles Brown dies the corresponding tuples from Patient and Surgery tables can be deleted without losing information on David Rosen. • Update: If John White comes in for third time, and has moved, we only need to change the Patient table 9/20/2000 Information Organization and Retrieval
2 NF Storage Anomalies • Insertion: Cannot enter the fact that a particular drug has a particular side effect unless it is given to a patient. • Deletion: If John White receives some other drug because of the penicillin rash, and a new drug and side effect are entered, we lose the information that penicillin cause a rash • Update: If drug side effects change (a new formula) we have to update multiple occurrences of side effects. 9/20/2000 Information Organization and Retrieval
Third Normal Form • A relation is said to be in Third Normal Form if there is no transitive functional dependency between nonkey attributes – When one nonkey attribute can be determined with one or more nonkey attributes there is said to be a transitive functional dependency. • The side effect column in the Surgery table is determined by the drug administered – Side effect is transitively functionally dependent on drug so Surgery is not 3 NF 9/20/2000 Information Organization and Retrieval
Third Normal Form 9/20/2000 Information Organization and Retrieval
Third Normal Form 9/20/2000 Information Organization and Retrieval
2 NF Storage Anomalies Removed • Insertion: We can now enter the fact that a particular drug has a particular side effect in the Drug relation. • Deletion: If John White recieves some other drug as a result of the rash from penicillin, but the information on penicillin and rash is maintained. • Update: The side effects for each drug appear only once. 9/20/2000 Information Organization and Retrieval
Boyce-Codd Normal Form • Most 3 NF relations are also BCNF relations. • A 3 NF relation is NOT in BCNF if: – Candidate keys in the relation are composite keys (they are not single attributes) – There is more than one candidate key in the relation, and – The keys are not disjoint, that is, some attributes in the keys are common 9/20/2000 Information Organization and Retrieval
Most 3 NF Relations are also BCNF – Is this one? 9/20/2000 Information Organization and Retrieval
BCNF Relations 9/20/2000 Information Organization and Retrieval
Fourth Normal Form • Any relation is in Fourth Normal Form if it is BCNF and any multivalued dependencies are trivial • Eliminate non-trivial multivalued dependencies by projecting into simpler tables 9/20/2000 Information Organization and Retrieval
Fifth Normal Form • A relation is in 5 NF if every join dependency in the relation is implied by the keys of the relation • Implies that relations that have been decomposed in previous NF can be recombined via natural joins to recreate the original relation. 9/20/2000 Information Organization and Retrieval
Effectiveness and Efficiency Issues for DBMS • Focus on the relational model • Any column in a relational database can be searched for values. • To improve efficiency indexes using storage structures such as BTrees and Hashing are used • But many useful functions are not indexable and require complete scans of the database 9/20/2000 Information Organization and Retrieval
Example: Text Fields • In conventional RDBMS, when a text field is indexed, only exact matching of the text field contents (or Greater-than and Lessthan). – Can search for individual words using pattern matching, but a full scan is required. • Text searching is still done best (and fastest) by specialized text search programs (Search Engines) that we will look at more later. 9/20/2000 Information Organization and Retrieval
Normalizing to death • Normalization splits database information across multiple tables. • To retrieve complete information from a normalized database, the JOIN operation must be used. • JOIN tends to be expensive in terms of processing time, and very large joins are very expensive. 9/20/2000 Information Organization and Retrieval
Advantages of RDBMS • Possible to design complex data storage and retrieval systems with ease (and without conventional programming). • Support for ACID transactions – Atomic – Consistent – Independent – Durable 9/20/2000 Information Organization and Retrieval
Advantages of RDBMS • Support for very large databases • Automatic optimization of searching (when possible) • RDBMS have a simple view of the database that conforms to much of the data used in businesses. • Standard query language (SQL) 9/20/2000 Information Organization and Retrieval
Disadvantages of RDBMS • Until recently, no support for complex objects such as documents, video, images, spatial or timeseries data. (ORDBMS are adding support these). • Often poor support for storage of complex objects. (Disassembling the car to park it in the garage) • Still no efficient and effective integrated support for things like text searching within fields. 9/20/2000 Information Organization and Retrieval
Assignment 2 • The following information should be turned in for the preliminary design of your personal database project. 1. 2. 3. • 9/20/2000 A general description of the data you will be using for the database, and what uses you might expect the database to have (should be expanded from the previous assignment). A preliminary data dictionary for the files and data elements of the database. You should have at least 5 files with some logical connections between them. The data dictionary consists of all of the attributes that you have identified for each entity, along with indication of whether the attribute is a primary key (or part of a primary key), and what format the data will be (e. g. : text, decimal number, integer, etc. ) Produce an entity-relationship diagram of the database OR a UML diagram. These will be preliminary design specifications, so do not feel that you must follow everything that you describe here in the final database design. Information Organization and Retrieval
- Slides: 68