db design / ER Modeling B Database Systems Database Design Wilhelm Steinbuss Room G2.04, ext 4052
db design / ER Modeling Database Design Conceptual Modeling (Entity Relationship Approach) –What are the entities and relationships in the enterprise? –What information (attributes) about these entities and relationships should we store in the database? Normalization (1NF,2NF,3NF,BCNF,4NF,5NF) check model for redundancies and related anomalies –Reducing the need for additional integrity constraints –The rules behind the common sense in finding the ‚best‘ assignment for the attributes Physical design (Implementation, Tuning) map the model to the features of the target dbms
db design / ER Modeling Introduction 1.1 Conceptual Design Why ER-Modeling? –a picture tells you more than 1000 words (ex.1) –hints for additional integrity constraints (ex.2) –independent of technical restrictions (ex.3) More transferable (between releases, vendors) More stable („essential model“)
db design / ER Modeling Normalization Why normalization ? Suppose table project is a result of conceptional design: employeenumber (A) departmentnumber (B) managernumber (C) projectnumber (unique within manager) (D) departmentname (E) percentage_project_time (F) (allocated by the specified manager) Functional dependency (e.g. B E) implies an integrity constraint !
db design / ER Modeling Integrity constraints Not null Primary key Unique constraint Foreign key Check constraint Trigger Example 5 emp table: Empno number(4) Enamevarchar(10) Jobvarchar(9) Mgrnumber(4) Hiredatedate Salnumber(7,2) Commnumber(7,2) Deptnonumber(2) _idvarchar(30)
db design / ER Modeling Physical design Example 3: a Person owns at least one address an address is assigned to at least one person Possible Implementations: –First address within person table –DEFERRABLE constraints –Nested table
db design / ER Modeling Entity Relationship Notation An information system contains all facts which are important for the enterprise Within a fact you assign attribute values to something Example: the person Linda McGee has the birthday The saving account 123 has the interest rate 3%
db design / ER Modeling Entity Everything you want to talk about (assign attribute values) is called an entity Examples: The person Linda McGee The saving account 123
db design / ER Modeling Entity Type An entity type is a set of entities with the same semantic meaning An entity type is called fundamental if in the fact is only one object involved; it is graphically represented by a rectangle Example:
db design / ER Modeling associative entity type An entity type is called associative if the fact is a statement about more than one objects; it is graphically represented by a rectangle and arrows pointing to the entity types which are referenced Example:
db design / ER Modeling Example: loan account A person could have more than one account An account is owned by at least one person For each account there have to be at least one security (the security owner must not be the owner of the account)
db design / ER Modeling Solution
db design / ER Modeling Solution (cont.) Additional requests: A security could hedge more than one account A person could own more than one security A security must be assigned to at least one person
db design / ER Modeling Exercise: Doctor’s practice A doctor’s practice want to store information about their patients over time ( e.g. blood sugar, blood pressure, cholesterol) A patient can have different blood values A blood value for a patient could be recorded more than once over time A patient could be treated with drugs. The time period and the dose of a drug should be recorded for a patient Within different time periods there are different dose rates (and a drug changes) possible. Add additional requirements if necessary.
db design / ER Modeling Attribute type Every attribute type has assigned a type (abstract data type) A type is a set of values together with a set of operations (not very good supported in dbms today; what a sense does it make to multiply two employeenumbers?) (the domain construct is usually only a restriction of a basic type)