Chapter 9: Designing Databases
Key physical database design decisions include:
1. Choosing a storage format for each attribute from the logical database model. 2. Grouping attributes from the logical database model into physical records. 3. Arranging related records in secondary memory (hard disks and magnetic tapes) so that records can be stored, retrieved and updated rapidly. 4. Selecting media and structures for storing data to make access more efficient.
Well-Structured Relation (or table)
A relation that contains a minimum amount of redundancy Allows users to insert, modify, and delete the rows without errors or inconsistencies
In what phase of the SDLC model is Database Design in?
Design: Databases
Second Normal Form (2NF)
Each nonprimary key attribute is identified by the whole key (called full functional dependency)
Types of View Integration problems:
synonyms (2 names 1 attribute) > get agreement on single, standard name homonyms> (1 name 2+attributes)>create a new name Dependencies between nonkeys> normalize new relation class/subclass (relationships may be hidden)> create a new name
Normalization:
the process of converting complex data structures into simple, stable data structures every nonprimary key attribute depends on the whole primary key
The most reliable method for identifying functional dependency
Knowledge of problem domain
Selecting a data type balances four objectives:
Minimize storage space. Represent all possible values of the field. Improve data integrity of the field. Support all data manipulations desired on the field.
Indexed ( storage, retrieval, rand retrieval on PK, multiple key retrieval, deleting rows, adding, rows, updating rows)
No wasted data space, extra index space Moderately fast Moderately fast Very fast w/ mutliple indexes Requires maintenance if dynamically allocated Requires maintenance of indexes if dynamically allocated easy buy requires index maintenance
Sequential ( storage, retrieval, rand retrieval on PK, multiple key retrieval, deleting rows, adding, rows, updating rows)
No wasted space Very fast Impractical Possible but requires scanning whole file Create wasted space/require reorganizing Requires rewriting file Usually requires rewriting
Third Normal Form (3NF)
Nonprimary key attributes do not depend on each other (i.e. no transitive dependencies)
Pros/Cons of Indexed File Organization
Pro: Allow for both random and sequential processing Con: Extra space required to store the indexes, extra time necessary to access and maintain indexes
First Normal Form (1NF)
Unique rows, no multivalued attributes All relations are in 1NF
Commonly used data types in Oracle 10i
VARCHAR2: max 4000 char CHAR: max 255 char ; min 1 LONG: 2 gb of variable length fields NUMBER: pos/neg values DATE BLOB: binary large object; can store 4 gb of binary date
Data Type:
a coding scheme recognized by system software for representing organizational data
Pointer:
a field of data that can be used to locate a related field or row of data
Sequential file organization:
a file organization in which rows in a file are stored in sequence according to a primary key value
Physical Table:
a named set of rows and columns that specifies the fields in each row of the table
Physical file:
a named set of table rows stored in a contiguous section of secondary memory
Relation:
a named, two-dimensional table of data; each relation consists of a set of named columns and an arbitrary number of unnamed rows
Functional Dependency:
a particular relationship between two attributes For a given relation, attribute B is functionally dependent on attribute A if, for every valid value of A, that value of A uniquely determines the value of B. The functional dependence of B on A is represented by A→B.
Foreign Key:
an attribute that appears as a nonprimary key attribute in one relation and as a primary key attribute (or part of a primary key) in another relation
Binary 1:N Relationship
is represented by adding the primary key attribute (or attributes) of the entity on the one side of the relationship as a foreign key in the relation that is on the many side of the relationship.
Binary or Unary 1:1 Relationship
is represented by any of the following choices: Add the primary key of A as a foreign key of B. Add the primary key of B as a foreign key of A. Both of the above > modeled as relation; primary key of that relation is same as for the entity type; foreign key is added to reference PK values
Range Control:
limits range of values that can be entered into field Both numeric and alphanumeric data
Two of the goals of physical table design are ______ and _____.
protection from failure or data loss security from unauthorized use.
Indexed file organization:
rows are stored either sequentially or nonsequentially, and an index is created that allows software to locate individual rows
For physical database design the following decisions need to be made:
Decide to create one or more fields for each attribute and determine a data type for each field. For each field, decide if it is calculated; needs to be coded or compressed; must have a default value or picture; or must have range, referential integrity, or null value controls. For each relation, decide if it should be denormalized to achieve desired processing efficiencies. Choose a file organization for each physical file. Select suitable controls for each file and the database.
Step 1: Represent entities
Each regular entity is transformed into a relation. The identifier of the entity type becomes the primary key (unique, nonredundant) of the corresponding relation. The entity type label is translated into a relation name.
Objectives for choosing file organization
Fast data retrieval High throughput for processing transactions Efficient use of storage space Protection from failures or data loss Minimizing need for reorganization Accommodating growth Security from unauthorized use
It is useful to transform the conceptual data model into a set of normalized relations. What are the steps?
Represent entities. Represent relationships. Normalize the relations. Merge the relations.
Calculated (or computed or derived) field:
a field that can be derived from other database fields common for an attribute to be mathematically related to other date value stored/requested
Hashed file organization:
a file organization in which the address for each row is determined using an algorithm
Recursive foreign key:
a foreign key in a relation that references the primary key values of that same relation
Deliverables for logical db design
accouting for every element on a system input/output normalized relations
Referential Integrity:
an integrity constraint specifying that the value (or existence) of an attribute in one relation depends on the value (or existence) of the same attribute in another relation
A relation is in third normal form (3NF) if it is in second normal form (2NF) and there are no ______ dependencies between _______ key attributes.
functional (transitive) ; nonprimary key attributes
Denormalization:
the process of splitting or combining normalized relations into physical tables based on affinity of use of rows and fields optimizes certain date processing activities at expense of others
Field:
the smallest unit of named application data recognized by system software Attributes from relations will be represented as fields
Three common situations where denormalization may be used:
-Two entities with a one-to-one relationship -A many-to-many relationship (associative entity) with nonkey attributes -Reference data
Properties of relations
-simple cell entries -column entries are from same set of values -each row is unique -sequence of columns can be interchanged without changing meaning/use -rows may be interchanged/stored in any sequence
Four key steps in logical database modeling and design:
1. Develop a logical data model for each known user interface for the application using normalization principles. 2. Combine normalized data requirements from all user interfaces into one consolidated logical database model (view integration). 3. Translate the conceptual E-R data model for the application into normalized data requirements. 4. Compare the consolidated logical database design with the translated E-R model and produce one final logical database model for the application.
File and database design occurs in which two steps?
1. Develop a logical database model, which describes data using notation that corresponds to a data organization used by a database management system. >Relational database model 2. Prescribe the technical specifications for computer files and databases in which to store the data. > Physical db design provides specs
Primary Key
An attribute whose value is unique across all occurrences of a relation
Hashed ( storage, retrieval, rand retrieval on PK, multiple key retrieval, deleting rows, adding, rows, updating rows)
Extra space may be needed to allow for addition and deletion of records Impractical Very fast not posible very easy very easy, except multiple keys requires extra work very easy
Techniques for file restoration include:
Periodically making a backup copy of a file. Storing a copy of each change to a file in a transaction log or audit trail. Storing a copy of each row before or after it is changed.
Three types of table partitioning:
Range partitioning: partitions are defined by nonoverlapping ranges of values for a specified attribute Hash partitioning: a table row is assigned to a partition by an algorithm and then maps the specified attribute value to a partition Composite partitioning: combines range and hash partitioning by first segregating data by ranges on the designated attribute, and then within each of these partitions
Guidelines for choosing indexes
Specific a unique index for the PK of each table Specify an index for foreign keys Specify an index for nonkey fields that are referenced in qualification, sorting and grouping commands for the purpose of retrieving data.
A relation is in second normal form (2NF) if any of the following conditions apply:
The primary key consists of only one attribute. No nonprimary key attributes exist in the relation. Every nonprimary key attribute is functionally dependent on the full set of primary key attributes.
Null Value
a special field value, distinct from zero, blank, or any other value, that indicates that the value for the field is missing or otherwise unknown
Index:
a table used to determine the location of rows in a file that satisfy some condition
File organization:
a technique for physically arranging the records of a file
Default Value:
a value a field will assume unless an explicit value is entered for that field
Deliverables for physical db design
converts relations into db tables programmers and db analysts code defintions of the database written in SQL
Relational database model:
data represented as a set of related tables or relations
To convert a relation into 2NF, ____ the relation into new relations using the attributes, called ____, that determine other attributes. The ____ are the primary keys of the new relations.
decompose; determinants; determinants
Instances/sample data in a relation __ ___ prove the existence of a functional dependency
do not
The last step in logical db design is:
merging relations to remove redundant relations prior to physical file and db design
Functional dependency is ___ a mathetical dependency
not
Secondary keys:
one or a combination of fields for which more than one row may have the same combination of values
Means of building data security into a file include:
Coding, or encrypting, the data in the file. Requiring data file users to identify themselves by entering user names and passwords. Prohibiting users from directly manipulating any data in the file by forcing users to work with a copy (real or virtual).
Unary M:N Relationship
Model as one relation, then Create a separate relation to represent the M:N relationship. The primary key of the new relation is a composite key of two attributes that both take their values from the same primary key. Any attribute associated with the relationship is included as a nonkey attribute in this new relation.
Information required for physical file and db design
Normalized relations, including volume estimates Definitions of each attribute Descriptions of where and when data are used, entered, retrieved, deleted, and updated (including frequencies) Expectations or requirements for response time and data integrity Descriptions of the technologies used for implementing the files and database
