You are on page 1of 103

Logical And Physical Database Design

1. 2. Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden. “Modern Database Management”. 4th Edition. Upper Saddle River, New Jersey:Prentice Hall (Pearson Educational, Inc), 2005 A. Silberschatz, H.F. Korth, S. Sudarshan. "Database System Concepts“ (4th Edition). McGrawHill, 2002.

KRISNA ADIYARTA PASCA SARJANA (MAGISTER KOMPUTER) UNIVERSITAS BUDI LUHUR JAKARTA

Objectives
„ „ „ „ „ „ „ „

Definition of terms List five properties of relations State two properties of candidate keys Define first, second, and third normal form Describe problems from merging relations Transform E-R and EER diagrams to relations Create tables with entity and relational integrity constraints Use normalization to convert anomalous tables to well-structured relations

Objectives
„ „ „ „ „ „ „ „

Definition of terms Describe the physical database design process Choose storage formats for attributes Select appropriate file organizations Describe three types of file organization Describe indexes and their appropriate use Translate a database model into efficient structures Know when and how to use denormalization

Relation „ „ Definition: A relation is a named. two-dimensional table of data Table consists of rows (records) and columns (attribute or field) „ Requirements for a table to qualify as a relation: … … … … … … It must have a unique name Every attribute value must be atomic (not multivalued. not composite) Every row must be unique (can’t have two rows with exactly the same values for all their fields) Attributes (columns) in tables must have unique names The order of the columns must be irrelevant The order of the rows must be irrelevant NOTE: all relations are in 1st Normal form .

Correspondence with E-R Model „ „ „ Relations (tables) correspond with entity types and with many-to-many relationship types Rows correspond with entity instances and with many-to-many relationship instances Columns correspond with attributes NOTE: The word relation (in relational database) is NOT the same as the word relationship (in E-R model) „ .

social security numbers. This is how we can guarantee that all rows are unique … Foreign keys are identifiers that enable a dependent relation (on the many side of a relationship) to refer to its parent relation (on the one side of the relationship) „ „ Keys can be simple (a single field) or composite (more than one field) Keys usually are used as indexes to speed up the response to user queries .Key Fields „ Keys are special fields that serve two main purposes: … Primary keys are unique identifiers of the relation in question. etc. Examples include employee numbers.

Schema for four relations (Pine Valley Furniture Company) Primary Key Foreign Key (implements 1:N relationship between customer and order) Combined. these are a composite primary key (uniquely identifies the order line)…individually they are foreign keys (implement M:N relationship between order and product) .

Entity Integrity … No primary key attribute may be null.Integrity Constraints „ Domain Constraints … Allowable values for an attribute. All primary key fields MUST have data .

Domain definitions enforce domain integrity constraints .

(Or the foreign key can be null) … For example: Delete Rules „ „ „ Restrict–don’t allow delete of “parent” side if related rows exist in “dependent” side Cascade–automatically delete “dependent” side rows that correspond with the “parent” side row to be deleted Set-to-Null–set the foreign key in the dependent side to null if deleting from the parent side Æ not allowed for weak entities .Integrity Constraints „ Referential Integrity–rule states that any foreign key value (on the relation of the many side) MUST match a primary key value in the relation of the one side.

Referential integrity constraints

Referential integrity constraints are drawn via arrows from dependent to parent table

Referential integrity constraints are implemented with foreign key to primary key references

Transforming EER Diagrams into Relations

Mapping Regular Entities to Relations
1. 2. 3.

Simple attributes: E-R attributes map directly onto the relation Composite attributes: Use only their simple, component attributes Multivalued Attribute–Becomes a separate relation with a foreign key taken from the superior entity

Mapping a regular entity (a) CUSTOMER entity type with simple attributes (b) CUSTOMER relation .

Mapping a composite attribute (a) CUSTOMER entity type with composite attribute (b) CUSTOMER relation with address detail .

Mapping an entity with a multivalued attribute (a) Multivalued attribute becomes a separate relation with foreign key (b) One–to–many relationship between original entity and new relation .

) Mapping Weak Entities …Becomes a separate relation with a foreign key taken from the superior entity …Primary key composed of: „ Partial identifier of weak entity „ Primary key of identifying relation (strong entity) .Transforming EER Diagrams into Relations (cont.

Example of mapping a weak entity a) Weak entity DEPENDENT .

Example of mapping a weak entity (cont.) b) Relations resulting from weak entity NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity Foreign key Composite primary key .

) Mapping Binary Relationships … One-to-Many–Primary key on the one side becomes a foreign key on the many side … Many-to-Many–Create a new relation with the primary keys of the two entities as its primary key … One-to-One–Primary key on the mandatory side becomes a foreign key on the optional side .Transforming EER Diagrams into Relations (cont.

no null value in the foreign key…this is because of the mandatory minimum cardinality .Example of mapping a 1:M relationship a) Relationship between customers and orders Note the mandatory one b) Mapping the relationship Foreign key Again.

Example of mapping an M:N relationship a) Completes relationship (M:N) The Completes relationship will need to become a separate relation .

Example of mapping an M:N relationship (cont.) b) Three resulting relations Composite primary key Foreign key Foreign key New intersection relation .

Example of mapping a binary 1:1 relationship a) In_charge relationship (1:1) Often in 1:1 relationships. . one direction is optional.

) b) Resulting relations Foreign key goes in the relation on the optional side. Matching the primary key on the mandatory side .Example of mapping a binary 1:1 relationship (cont.

Transforming EER Diagrams into Relations (cont.) Mapping Associative Entities …Identifier „ Default Not Assigned primary key for the association relation is composed of the primary keys of the two entities (as in M:N relationship) …Identifier „ It Assigned is natural and familiar to end-users „ Default identifier may not be unique .

Example of mapping an associative entity a) An associative entity .

) b) Three resulting relations Composite primary key formed from the two foreign keys .Example of mapping an associative entity (cont.

Example of mapping an associative entity with an identifier a) SHIPMENT associative entity .

) b) Three resulting relations Primary key differs from foreign keys .Example of mapping an associative entity with an identifier (cont.

) Mapping Unary Relationships … One-to-Many–Recursive foreign key in the same relation … Many-to-Many–Two relations: „ One for the entity type „ One for an associative relation in which the primary key has two attributes. both taken from the primary key of the entity .Transforming EER Diagrams into Relations (cont.

Mapping a unary 1:N relationship (a) EMPLOYEE entity with unary relationship (b) EMPLOYEE relation with recursive foreign key .

Mapping a unary M:N relationship (a) Bill-of-materials relationships (M:N) (b) ITEM and COMPONENT relations .

Transforming EER Diagrams into Relations (cont.) Mapping Ternary (and n-ary) Relationships …One relation for each entity and one for the associative entity …Associative entity has foreign keys to each entity in the relationship .

Mapping a ternary relationship a) PATIENT TREATMENT Ternary relationship with associative entity .

) b) Mapping the ternary relationship PATIENT TREATMENT Remember that the primary key MUST be unique This is why treatment date and time are included in the composite primary key But this makes a very cumbersome key… It would be better to create a surrogate key like Treatment# .Mapping a ternary relationship (cont.

) Mapping Supertype/Subtype Relationships … One relation for supertype and for each subtype … Supertype attributes (including identifier and subtype discriminator) go into supertype relation … Subtype attributes go into each subtype. primary key of supertype relation also becomes primary key of subtype relation … 1:1 relationship established between supertype and each subtype.Transforming EER Diagrams into Relations (cont. with supertype as primary table .

Supertype/subtype relationships .

Mapping Supertype/subtype relationships to relations These are implemented as one-to-one relationships .

well-structured relations .Data Normalization „ Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of data „ The process of decomposing relations with anomalies to produce smaller.

delete. and update rows without causing data inconsistencies Goal is to avoid anomalies … Insertion Anomaly–adding new rows forces user to create duplicate data … Deletion Anomaly–deleting rows may cause a loss of data that would be needed for other future rows … Modification Anomaly–changing data in a row forces changes to other rows because of duplication General rule of thumb: A table should not pertain to more than one entity type .Well-Structured Relations „ „ A relation that contains minimal data redundancy and allows users to insert.

Example Question–Is this a relation? Question–What’s the primary key? Answer–Yes: Unique rows and no multivalued attributes Answer–Composite: Emp_ID. Course_Title .

This results in data duplication and an unnecessary dependency between the entities . we lose information about the existence of a Tax Acc class Modification–giving a salary increase to employee 100 forces us to update multiple records Why do these anomalies exist? Because there are two themes (entity types) in this one relation.Anomalies in this Table „ „ „ Insertion–can’t enter a new employee without having the employee take a class Deletion–if we remove employee 140.

perhaps there is both credit card number and SS# in a table…in this case both are candidate keys … Each non-key field is functionally dependent on every candidate key . One of the candidate keys will become the primary key „ E.Functional Dependencies and Keys Functional Dependency: The value of one attribute (the determinant) determines the value of another attribute „ Candidate Key: „ …A unique identifier.g.

. A relation in Third normal form is also in 2NF and 1NF.Normalization Normalization Relations can fall into one or more categories (or classes) called Normal Forms Normal Form: A class of relations free from a certain set of modification anomalies. Normal forms are given name such as: First normal form (1NF) Second normal form (2NF) Third normal form (3NF) Boyce-Codd normal form (BCNF) Fourth normal form (4NF) Fifth normal form (5NF) •These forms are cumulative.

Steps in normalization .

4. then you can meet the unique row requirement.00 100. Symbol.00 33.The order of columns is insignificant.First Normal Form (1NF) •A relation is in first normal form if it meets the definition of a relation: 1.Each column (attribute) value must be a single value only. 5. 3. •If you have a key defined for the relation. Close_Price) Company IBM IBM IBM Netscape Netscape Symbol IBM IBM IBM NETS NETS Date 01/05/94 01/06/94 01/07/94 01/05/94 01/06/94 Close Price 101.50 102.00 112. Date.No two rows (tuples) in a relation can be identical. •Example relation in 1NF: STOCKS (Company.The order of the rows (tuples) is insignificant. 6.00 .All values for a given column (attribute) must be of the same type. 2.Each column (attribute) name must be unique.

•In the example below. Date •The following example relation is not in 2NF: STOCKS (Company.00 . CA Date 01/05/94 01/06/94 01/07/94 01/05/94 01/06/94 Close Price 101. Date -> Close Price Symbol. Symbol. Headquarters Symbol -> Company.50 102. •This is one reason why we often use artificial identifiers as keys. NY Armonk. Close_Price) Company.Second Normal Form (2NF) •A relation is in second normal form (2NF) if all of its non-key attributes are dependent on all of the key. Date -> Close Price Company -> Symbol. •Relations that have a single attribute for a key are automatically in 2NF. Headquarters Company IBM IBM IBM Netscape Netscape Symbol IBM IBM IBM NETS NETS Headquarters Armonk. Date.00 112. CA Sunyvale. NY Armonk. NY Sunyvale.00 100. Headquarters. Date and Symbol.00 33. Close Price is dependent on Company.

Date -> Close Price.Second Normal Form (2NF) Consider that Company. However: Company -> Headquarters This violates the rule for 2NF.00 33. consider the insertion and deletion anomalies. NY Sunnyvale. Date. Also. Date as our key. Close_Price) Symbol IBM IBM IBM NETS NETS Date 01/05/94 01/06/94 01/07/94 01/05/94 01/06/94 Close Price Company 101. Headquarters) STOCKS (Symbol.50 102. •One Solution: Split this up into two relations: COMPANY (Company.00 112. Symbol. Headquarters Symbol -> Company. Date -> Close Price . So we might use Company. CA IBM Netscape Symbol.00 Company -> Symbol. Headquarters Symbol IBM NETS Headquarters Armonk.00 100.

Third Normal Form (3NF) •A relation is in third normal form (3NF) if it is in second normal form and it contains no transitive dependencies. Section -> Classroom. Professor •Example: At Rutgers: Course_ Index_Num -> Course_Num. Section -> Classroom. Section Course_Num. •Consider relation R containing attributes A. B and C. •Example: At CUNY: Course_Code -> Course_Num. If A -> B and B -> C then A -> C •Transitive Dependency: Three attributes with the above dependencies. Section Course_Num. Professor .

Third Normal Form (3NF) Example: Company IBM AT&T County Putnam Bergen Tax Rate 28% 26% Company -> County and County -> Tax Rate thus Company -> Tax Rate •What happens if we remove AT&T ? We loose information about 2 different themes. •Split this up into two relations: Company IBM AT&T County Putnam Bergen County Putnam Bergen Tax Rate 28% 26% Company -> County County -> Tax Rate .

•Those determinants that are keys we initially call candidate keys. Consider the following example: Funds consist of one or more Investment Types. •Recall that not all determinants are keys. InvestmentType -> Manager Manager -> InvestmentType . we select a single candidate key to be the primary key for the relation. Funds are managed by one or more Managers Investment Types can have one more Managers Managers only manage one type of investment.Boyce-Codd Normal Form (BCNF) •A relation is in BCNF if every determinant is a candidate key. FundID 99 99 33 22 11 InvestmentType Common Stock Municipal Bonds Common Stock Growth Stocks Common Stock Manager Smith Jones Green Brown Smith FundID. Manager -> InvestmentType FundID. •Eventually.

InvestmentType to uniquely identify a tuple in the relation. InvestmentType." FundID InvestmentTyp Manage e r FundID. 2NF because all of the non-key attributes (Manager) is dependant on all of the key.3NF because there are no transitive dependencies. • Consider what happens if we delete the tuple with FundID 22. InvestmentType -> Manager Manager -> InvestmentType 99 99 33 22 11 Common Stock Municipal Bonds Common Stock Growth Stocks Common Stock Smith Jones Green Brown Smith . 2NF or 3NF ? Given we pick FundID. • Similarly. Manager) in 1NF. We loose the fact that Brown manages the InvestmentType "Common Stocks. Manager -> InvestmentType FundID. Manager to uniquely identify a tuple. • Is this relation R(FundID. InvestmentType as the Primary Key: 1NF for sure. the combination FundID and Manager also form a candidate key because we can use FundID.Boyce-Codd Normal Form (BCNF) • The combination FundID and InvestmentType form a candidate key because we can use FundID. • Manager by itself is not a candidate key because we cannot use Manager alone to uniquely identify a tuple in the relation.

2. we have retained the determinant "Manager" in the original relation Rorig. For our example: Rorig(FundID. Manager) In this last step. Manager) 1. create a new relation from the functional dependency. Manager YES Manager NO 3. Which determinants can act as keys ? FundID. 3. • 1. InvestmentType. See if each determinant can act as a key (candidate keys). For any determinant that is not a candidate key. Manager Manager 2.Boyce-Codd Normal Form (BCNF) The following are steps to normalize a relation into BCNF: List all of the determinants. Create a new relation from the functional dependency: Rnew(Manager. The determinants are: FundID. InvestmentType YES FundID. InvestmentType FundID. Retain the determinant in the original relation. InvestmentType) Rorig(FundID. .

• . and C. There must be at least 3 attributes in the relation. B. 2. B and C are independent of one another. • Multivalued Dependency: A type of functional dependency where the determinant can determine more than one value. example: Student has one or more majors. Given A. for example. one can determine multiple values of C.Fourth Normal Form (4NF) A relation is in fourth normal form if it is in BCNF and it contains multivalued dependencies. Given A. • More formally. one can determine multiple values of B. 3. Student participates in one or more activities. call them A. there are 3 criteria: 1.

Fourth Normal Form (4NF) StudentID 100 100 100 100 200 Major CIS CIS Accounting Accounting Marketing Activities Baseball Volleyball Baseball Volleyball Swimming StudentID ->> Major StudentID ->> Activities Portfolio ID 999 999 999 999 888 Stock Fund Janus Fund Janus Fund Scudder Global Fund Scudder Global Fund Kaufmann Fund Bond Fund Municipal Bonds Dreyfus Short-Intermediate Municipal Bond Fund Municipal Bonds Dreyfus Short-Intermediate Municipal Bond Fund T. Rowe Price Emerging Markets Bond Fund .

2.Fourth Normal Form (4NF) • 1. Insertion anomaly: Cannot add a stock fund without adding a bond fund (NULL Value). 4. Stock Fund and Bond Fund form a multivalued dependency on Portfolio ID. 3. Latter two attributes are independent of one another. PortfolioID ->-> Stock Fund PortfolioID ->-> Bond Fund • . A few characteristics: No regular functional dependencies All three attributes taken together form the key. Must always maintain the combinations to preserve the meaning.

Fourth Normal Form (4NF) Resolution: Split into two tables with the common key: Portfolio ID 999 999 999 999 888 Portfolio ID 999 999 888 Stock Fund Janus Fund Janus Fund Scudder Global Fund Scudder Global Fund Kaufmann Fund Stock Fund Janus Fund Scudder Global Fund Kaufmann Fund Bond Fund Municipal Bonds Dreyfus Short-Intermediate Municipal Bond Fund Municipal Bonds Dreyfus Short-Intermediate Municipal Bond Fund T. Rowe Price Emerging Markets Bond Fund . Rowe Price Emerging Markets Bond Fund Portfolio ID 999 999 888 Bond Fund Municipal Bonds Dreyfus Short-Intermediate Municipal Bond Fund T.

Fifth Normal Form (5NF) There are certain conditions under which after decomposing a relation. . it cannot be reassembled back into its original form.

Name. City. Name. City. • In such cases.each customer address lookup requires we look in two relations (tables). Address.De-Normalization • Consider the following relation: CUSTOMER (CustomerID. Zip -> City. State) • We may pay a performance penalty . we may de-normalize the relations to achieve a performance improvement. . State • We can normalize this into DK/NF by splitting the CUSTOMER relation into two: CUSTOMER (CustomerID. Zip) CODES (Zip. State. Address. Zip) • This relation is not in DK/NF because it contains a functional dependency not implied by the key.

Office. Phone ) Note: Keys are underlined. This is tough to do. Task. • Example Data: Name Project Task Office Floor Phone Bill Bill Bill Bill Sue Sue Sue Ed 100X 100X 200Y 200Y 100X 200Y 300Z 100X T1 T2 T1 T2 T33 T33 T33 T2 400 400 400 400 442 442 442 588 4 4 4 4 4 4 4 5 1400 1400 1400 1400 1442 1442 1442 1588 .All-in-One Example • Many of you asked for a "complete" example that would run through all of the normal forms from beginning to end using the same tables. Project. but here is an attempt: • Example relation: EMPLOYEE ( Name.

• Task is the current task being worked on. Sue is working on 3. Question : First Normal Form Assume the key is Name.All-in-One Example • Name is the employee's name • Project is the project they are working on. Project. • Office is the office number for the employee. Examples of a task might be faxing a memo or holding a meeting. Bill is now working on Tasks T1 and T2. • Floor is the floor on which the office is located. Note that Tasks are independent of the project. Task. • Phone is the phone extension. Note this is associated with the phone in the given office. Bill works in office number 400. Is EMPLOYEE in 1NF ? . Bill is working on two different projects.

All-in-One Example Second Normal Form •List all of the functional dependencies for EMPLOYEE. Floor. Phone) . Office. EMPLOYEE_PROJECT_TASK (Name. •Are all of the non-key attributes dependant on all of the key ? •Split into two relations EMPLOYEE_PROJECT_TASK and EMPLOYEE_OFFICE_PHONE. Project. Name Project Task Task) Name Bill Bill Bill Bill Sue Sue Sue Ed Project 100X 100X 200Y 200Y 100X 200Y 300Z 100X Task T1 T2 T1 T2 T33 T33 T33 T2 Office 400 400 400 400 442 442 442 588 Floor 4 4 4 4 4 4 4 5 Phone 1400 1400 1400 1400 1442 1442 1442 1588 Bill Sue Ed Bill Bill Bill Bill Sue Sue Sue Ed Name 100X 100X 200Y 200Y 100X 200Y 300Z 100X Office 400 442 588 T1 T2 T1 T2 T33 T33 T33 T2 Floor 4 4 5 Phone 1400 1442 1588 EMPLOYEE_OFFICE_PHONE (Name.

Project.All-in-One Example Third Normal Form •Assume each office has exactly one phone number. Office. •EMPLOYEE_PROJECT_TASK (Name. Floor) Name Office Floor Bill 400 4 Sue 442 4 Ed 588 5 EMPLOYEE_PHONE (Office. •Are there any transitive dependencies ? •Where are the modification anomalies in EMPLOYEE_OFFICE_PHONE ? •Split EMPLOYEE_OFFICE_PHONE. Phone) Office 400 442 588 Phone 1400 1442 1588 Name Bill Bill Bill Bill Sue Sue Sue Ed Project 100X 100X 200Y 200Y 100X 200Y 300Z 100X Task T1 T2 T1 T2 T33 T33 T33 T2 . Task) EMPLOYEE_OFFICE (Name.

All-in-One Example Boyce-Codd Normal Form •List all of the functional dependencies for EMPLOYEE_PROJECT_TASK. Look at the determinants. EMPLOYEE_OFFICE and EMPLOYEE_PHONE. •Are all determinants candidate keys ? .

Task ) .All-in-One Example Forth Normal Form •Are there any multivalued dependencies ? •What are the modification anomalies ? •Split EMPLOYEE_PROJECT_TASK. •EMPLOYEE_PROJECT (Name. Project ) Name Bill Bill Bill Bill Sue Sue Sue Ed Project 100X 100X 200Y 200Y 100X 200Y 300Z 100X Task T1 T2 T1 T2 T33 T33 T33 T2 Name Bill Bill Sue Sue Sue Ed Name Bill Bill Sue Ed Project 100X 200Y 100X 200Y 300Z 100X Task T1 T2 T33 T2 EMPLOYEE_TASK (Name.

Office. Phone) .All-in-One Example Name Bill Sue Ed Office 400 442 588 Floor 4 4 5 •EMPLOYEE_OFFICE (Name. Floor) Office 400 442 588 Phone 1400 1442 1588 •R4 (Office.

.Write out all of the functional dependencies 4.(optionally) Write out some example data. we did the following: 1.All-in-One Example At each step of the process.Write out the relation 2.Starting with 1NF. 3. go through each normal form and state why the relation is in the given normal form.

State. City. City. Street. Zip. City New Brunswick Old Bridge State Zip NJ NJ Phone 07101 732-555-1212 07066 908-555-1212 Functional Dependencies CustomerID -> Name. Name. Phone) Example Data CustomerID C101 C102 Name Bill Smith Mary Green Street 123 First St.All-in-One Example Another short example Consider the following example of normalization for a CUSTOMER relation. 11 Birch St. State. Phone Zip -> City. Relation Name CUSTOMER (CustomerID. Street. State . Zip.

. •3NF There are no transitive dependencies. State) •Check both CUSTOMER and ZIPCODE to ensure they are both in 1NF up to BCNF. Zip. •2NF All non key attributes are dependent on all of the key.All-in-One Example Normalization •1NF Meets the definition of a relation. City. Name. •BCNF Relation CUSTOMER is not in BCNF because one of the determinants Zip can not act as a key for the entire relation. consider de-normalization. Solution: Split CUSTOMER into two relations: CUSTOMER (CustomerID. •4NF There are no multi-valued dependencies in either CUSTOMER or ZIPCODES. Street. Phone) ZIPCODES (Zip. As a final step.

they may not be after merging … Supertype/subtype relationships–may be hidden prior to merging .Merging Relations „ „ View Integration–Combining entities from multiple ER models into common relations Issues to watch out for when merging entities from different ER models: … Synonyms–two or more attributes with different names but same meaning … Homonyms–attributes with same name but different meanings … Transitive dependencies–even if relations are in 3NF prior to merging.

not just within a single relation „ Corresponds with the concept of an object ID in object-oriented systems .Enterprise Keys „ Primary keys that are unique in the whole database.

Enterprise keys a) Relations with enterprise key b) Sample data with enterprise key .

security. and recoverability „ .Physical Database Design Purpose–translate the logical description of data into the technical specifications for storing and retrieving data „ Goal–create a design for storing data that will provide adequate performance and insure database integrity.

Physical Design Process Inputs zNormalized zVolume relations Decisions zAttribute zPhysical estimates definitions time expectations Leads to data types zAttribute zResponse zData record descriptions (doesn’t always match logical design) security needs needs zFile organizations and database architectures zBackup/recovery zIntegrity zDBMS zIndexes expectations zQuery technology used optimization .

Composite usage map .

Composite usage map (cont.)

Data volumes

Composite usage map (cont.)

Access Frequencies (per hour)

Composite usage map (cont.)
Usage analysis:
140 purchased parts accessed per hour Î 80 quotations accessed from these 140 purchased part accesses Î 70 suppliers accessed from these 80 quotation accesses

) Usage analysis: 75 suppliers accessed per hour Î 40 quotations accessed from these 75 supplier accesses Î 40 purchased parts accessed from these 40 quotation accesses .Composite usage map (cont.

Designing Fields „ Field: smallest unit of data in database „ Field design …Choosing data type …Coding. compression. encryption …Controlling data integrity .

) . etc.Choosing Data Types „ „ „ „ „ „ „ CHAR–fixed-length character VARCHAR2–variable-length character (memo) LONG–large number NUMBER–positive/negative number INEGER–positive/negative whole number DATE–actual date BLOB–binary large object (good for graphics. sound clips.

Example code look-up table Code saves space. but costs an additional lookup to obtain actual value .

Field Data Integrity „ „ „ „ Default value–assumed value if no explicit value Range control–allowable value limitations (constraints or validation rules) Null value control–allowing or prohibiting empty fields Referential integrity–range control (and null value allowances) for foreign-key to primarykey match-ups Sarbanes-Oxley Act (SOX) legislates importance of financial data integrity .

g.. ignore missing data unless the value is significant (sensitivity testing) Triggers can be used to perform these operations .Handling Missing Data „ „ „ Substitute an estimate of the missing value (e. using a formula) Construct a report listing missing values In programs.

Physical Records Physical Record: A group of fields stored in adjacent memory locations and retrieved together as a unit „ Page: The amount of data read or written in one I/O operation „ Blocking Factor: The number of physical records per page „ .

Denormalization „ Transforming normalized relations into unnormalized physical record specifications „ Benefits: … Can improve performance (speed) by reducing number of table lookups (i.e. reduce number of necessary join queries) „ Costs (due to data duplication) … Wasted storage space … Data integrity/consistency threats „ Common denormalization opportunities … One-to-one relationship … Many-to-many relationship with attributes) … Reference data (1:N relationship where 1-side has data not used in any other relationship) .

A possible denormalization situation: two entities with one-to-one relationship .

A possible denormalization situation: a many-to-many relationship with nonkey attributes Extra table access required Null description possible .

A possible denormalization situation: reference data Extra table access required Data duplication .

Hash Partitioning.Partitioning „ Horizontal Partitioning: Distributing the rows of a table into several separate files … Useful for situations where different users need access to different rows … Three types: Key Range Partitioning. or Composite Partitioning „ Vertical Partitioning: Distributing the columns of a table into several separate relations … Useful for situations where different users need access to different columns … The primary key must be repeated in each file „ Combinations of Horizontal and Vertical Partitions often correspond with User Schemas (user views) .

recovery … Load balancing: Partitions stored on different disks.) „ Advantages of Partitioning: … … Efficiency: Records used together are grouped together Local optimization: Each partition can be optimized for performance … Security.Partitioning (cont. reduces contention … Take advantage of parallel processing capability „ Disadvantages of Partitioning: … … … Inconsistent access speed: Slow retrievals across partitions Complexity: Non-transparent partitioning Extra space or update time: Duplicate data. access from multiple partitions .

Data Replication „ Purposely storing the same data in multiple locations of the database „ Improves performance by allowing multiple users to access the same data at the same time with minimum contention „ Sacrifices data integrity due to data duplication „ Best for data that is not updated often .

Designing Physical Files „ Physical File: …A named portion of secondary memory allocated for the purpose of storing physical records … Tablespace–named set of disk storage elements in which physical files for database tables can be stored … Extent–contiguous section of disk space „ Constructs to link two pieces of data: … Sequential storage … Pointers–field of data that can be used to locate related fields or records .

Physical file terminology in an Oracle environment .

File Organizations „ „ Technique for physically arranging records of a file on secondary storage Factors for selecting file organization: … Fast data retrieval and throughput … Efficient storage space utilization … Protection from failure and data loss … Minimizing need for reorganization … Accommodating growth … Security from unauthorized use „ Types of file organizations … Sequential … Indexed … Hashed .

Sequential file organization 1 2 Records of the file are stored in sequence by the primary key field values If sorted – every insert or delete requires resort If not sorted Average time to find desired record = n/2 n .

Indexed File Organizations „ „ „ „ Index–a separate table that contains organization of records for quick retrieval Primary keys are automatically indexed Oracle has a CREATE INDEX operation. and MS ACCESS allows indexes to be created for most field types Indexing approaches: … B-tree index … Bitmap index … Hash Index … Join Index .

B-tree index Leaves of the tree are all at same level Æ consistent access time uses a tree search Average time to find desired record = depth of the tree .

Hashed file or index organization Hash algorithm Usually uses divisionremainder to determine record position. Records with same position are grouped in lists .

Bitmap index index organization Bitmap saves on space requirements Rows .possible values of the attribute Columns .table rows Bit indicates whether the attribute of a row has the values .

Join Indexes–speeds up join operations .