Moder Systems Aalysis ad Desig Seveth Editio Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Desigig Databases
Learig Objectives ü Cocisely defie each of the followig key database desig terms: relatio, primary key, ormalizatio, fuctioal depedecy, foreig key, referetial itegrity, field, data type, ull value, deormalizatio, file orgaizatio, idex, ad secodary key. ü Explai the role of desigig databases i the aalysis ad desig of a iformatio system. ü Trasform a etity-relatioship (E-R) diagram ito a equivalet set of well-structured (ormalized) relatios. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 2
Learig Objectives (Cot.) ü Merge ormalized relatios from separate user views ito a cosolidated set of well-structured relatios. ü Choose storage formats for fields i database tables. ü Traslate well-structured relatios ito efficiet database tables. ü Explai whe to use differet types of file orgaizatios to store computer files. ü Describe the purpose of idexes ad the importat cosideratios i selectig attributes to be idexed. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 3
Itroductio FIGURE 9-1 Systems developmet life cycle with desig phase highlighted 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 4
Database Desig File ad database desig occurs i two steps. 1. Develop a logical database model, which describes data usig otatio that correspods to a data orgaizatio used by a database maagemet system. Relatioal database model 2. Prescribe the techical specificatios for computer files ad databases i which to store the data. Physical database desig provides specificatios Logical ad physical database desig i parallel with other system desig steps 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 5
The Process of Database Desig FIGURE 9-2 Relatioship betwee data modelig ad the systems developmet life cycle 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 6
The Process of Database Desig (Cot.) Four key steps i logical database modelig ad desig: 1. Develop a logical data model for each kow user iterface for the applicatio usig ormalizatio priciples. 2. Combie ormalized data requiremets from all user iterfaces ito oe cosolidated logical database model (view itegratio). 3. Traslate the coceptual E-R data model for the applicatio ito ormalized data requiremets. 4. Compare the cosolidated logical database desig with the traslated E-R model ad produce oe fial logical database model for the applicatio. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 7
Physical Database Desig Key physical database desig decisios iclude: Choosig a storage format for each attribute from the logical database model. Groupig attributes from the logical database model ito physical records. Arragig related records i secodary memory (hard disks ad magetic tapes) so that records ca be stored, retrieved ad updated rapidly. Selectig media ad structures for storig data to make access more efficiet. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 8
Deliverables ad Outcomes Logical database desig Must accout for every data elemet o a system iput or output Normalized relatios are the primary deliverable. Physical database desig Coverts relatios ito database tables Programmers ad database aalysts code the defiitios of the database. Writte i Structured Query Laguage (SQL) 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 9
FIGURE 9-3 (d) Coceptual data model ad trasformed relatios 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 10
Relatioal Database Model Relatioal database model: data represeted as a set of related tables or relatios Relatio: a amed, two-dimesioal table of data; each relatio cosists of a set of amed colums ad a arbitrary umber of uamed rows 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 11
Relatioal Database Model (Cot.) Relatios have several properties that distiguish them from orelatioal tables: Etries i cells are simple. Etries i colums are from the same set of values. Each row is uique. The sequece of colums ca be iterchaged without chagig the meaig or use of the relatio. The rows may be iterchaged or stored i ay sequece. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 12
Well-Structured Relatio ad Primary Keys Well-Structured Relatio (or table) A relatio that cotais a miimum amout of redudacy Allows users to isert, modify, ad delete the rows without errors or icosistecies Primary Key A attribute whose value is uique across all occurreces of a relatio All relatios have a primary key. This is how rows are esured to be uique. A primary key may ivolve a sigle attribute or be composed of multiple attributes. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 13
Normalizatio ad Rules of Normalizatio Normalizatio: the process of covertig complex data structures ito simple, stable data structures The result of ormalizatio is that every oprimary key attribute depeds upo the whole primary key. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 14
Normalizatio ad Rules of Normalizatio (Cot.) First Normal Form (1NF) Uique rows, o multivalued attributes All relatios are i 1NF Secod Normal Form (2NF) Each oprimary key attribute is idetified by the whole key (called full fuctioal depedecy) Third Normal Form (3NF) Noprimary key attributes do ot deped o each other (i.e. o trasitive depedecies) 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 15
Fuctioal Depedecies ad Primary Keys Fuctioal Depedecy: a particular relatioship betwee two attributes For a give relatio, attribute B is fuctioally depedet o attribute A if, for every valid value of A, that value of A uiquely determies the value of B. The fuctioal depedece of B o A is represeted by A B. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 16
Fuctioal Depedecies ad Primary Keys (Cot.) Fuctioal depedecy is ot a mathematical depedecy. Istaces (or sample data) i a relatio do ot prove the existece of a fuctioal depedecy. Kowledge of problem domai is most reliable method for idetifyig fuctioal depedecy. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 17
Secod Normal Form (2NF) A relatio is i secod ormal form (2NF) if ay of the followig coditios apply: The primary key cosists of oly oe attribute. No oprimary key attributes exist i the relatio. Every oprimary key attribute is fuctioally depedet o the full set of primary key attributes. To covert a relatio ito 2NF, decompose the relatio ito ew relatios usig the attributes, called determiats, that determie other attributes. The determiats are the primary keys of the ew relatios. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 18
Third Normal Form (3NF) A relatio is i third ormal form (3NF) if it is i secod ormal form (2NF) ad there are o fuctioal (trasitive) depedecies betwee two (or more) oprimary key attributes. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 19
2014 Pearso Educatio, Ic. Publishig as Pretice Hall 20
Third Normal Form (3NF) (Cot.) Foreig Key: a attribute that appears as a oprimary key attribute i oe relatio ad as a primary key attribute (or part of a primary key) i aother relatio Referetial Itegrity: a itegrity costrait specifyig that the value (or existece) of a attribute i oe relatio depeds o the value (or existece) of the same attribute i aother relatio 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 21
Trasformig E-R Diagrams ito Relatios It is useful to trasform the coceptual data model ito a set of ormalized relatios. Steps Represet etities. Represet relatioships. Normalize the relatios. Merge the relatios. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 22
Represetig Etities Each regular etity is trasformed ito a relatio. The idetifier of the etity type becomes the primary key of the correspodig relatio. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 23
Represetig Etities The primary key must satisfy the followig two coditios. The value of the key must uiquely idetify every row i the relatio. The key should be oredudat. The etity type label is traslated ito a relatio ame. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 24
Biary 1:N ad 1:1Relatioships The procedure for represetig relatioships depeds o both the degree of the relatioship uary, biary, terary ad the cardialities of the relatioship. Biary 1:N Relatioship is represeted by addig the primary key attribute (or attributes) of the etity o the oe side of the relatioship as a foreig key i the relatio that is o the may side of the relatioship. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 25
Biary 1:N ad 1:1Relatioships (Cot.) Biary or Uary 1:1 Relatioship is represeted by ay of the followig choices: Add the primary key of A as a foreig key of B. Add the primary key of B as a foreig key of A. Both of the above 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 26
2014 Pearso Educatio, Ic. Publishig as Pretice Hall 27
Biary ad Higher-Degree M:N Relatioships Create aother relatio ad iclude primary keys of all relatios as primary key of ew relatio 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 28
2014 Pearso Educatio, Ic. Publishig as Pretice Hall 29
Uary Relatioships Uary 1:N Relatioship Is modeled as a relatio Primary key of that relatio is the same as for the etity type Foreig key is added to the relatio that refereces the primary key values Recursive foreig key: a foreig key i a relatio that refereces the primary key values of that same relatio 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 30
Uary Relatioships Uary M:N Relatioship Model as oe relatio, the Create a separate relatio to represet the M:N relatioship. The primary key of the ew relatio is a composite key of two attributes that both take their values from the same primary key. Ay attribute associated with the relatioship is icluded as a okey attribute i this ew relatio. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 31
FIGURE 9-13 Two uary relatioships (a) EMPLOYEE with Maages relatioship (1:N) (b) Bill-of-materials structure (M:N) 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 32
Mergig Relatios Purpose is to remove redudat relatios The last step i logical database desig Prior to physical file ad database desig 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 33
View Itegratio Problems Must uderstad the meaig of the data ad be prepared to resolve ay problems that arise i the process Syoyms: two differet ames used for the same attribute Whe mergig, get agreemet from users o a sigle, stadard ame. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 34
View Itegratio Problems (Cot.) Homoyms: a sigle attribute ame that is used for two or more differet attributes. Resolved by creatig a ew ame Depedecies betwee okeys depedecies may be created as a result of view itegratio To resolve, the ew relatio must be ormalized 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 35
View Itegratio Problems (Cot.) Class/Subclass relatioships may be hidde i user views or relatios Resolved by creatig a ew ame 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 36
FIGURE 9-16 Class diagram correspodig to ormalized relatios of Hoosier Burger s ivetory cotrol system 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 37
Relatios for Hoosier Burger 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 38
Physical File ad Database Desig The followig iformatio is required: Normalized relatios, icludig volume estimates Defiitios of each attribute Descriptios of where ad whe data are used, etered, retrieved, deleted, ad updated (icludig frequecies) Expectatios or requiremets for respose time ad data itegrity Descriptios of the techologies used for implemetig the files ad database 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 39
Desigig Fields Field: the smallest uit of amed applicatio data recogized by system software Attributes from relatios will be represeted as fields Data Type: a codig scheme recogized by system software for represetig orgaizatioal data 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 40
Choosig Data Types Selectig a data type balaces four objectives: Miimize storage space. Represet all possible values of the field. Improve data itegrity of the field. Support all data maipulatios desired o the field. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 41
2014 Pearso Educatio, Ic. Publishig as Pretice Hall 42
Calculated Fields Calculated (or computed or derived) field: a field that ca be derived from other database fields It is commo for a attribute to be mathematically related to other data. The calculate value is either stored or computed whe it is requested. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 43
Cotrollig Data Itegrity Default Value: a value a field will assume uless a explicit value is etered for that field Rage Cotrol: limits rage of values that ca be etered ito field Both umeric ad alphaumeric data Referetial Itegrity: a itegrity costrait specifyig that the value (or existece) of a attribute i oe relatio depeds o the value (or existece) of the same attribute i aother relatio Null Value: a special field value, distict from zero, blak, or ay other value, that idicates that the value for the field is missig or otherwise ukow 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 44
Desigig Physical Tables Relatioal database is a set of related tables. Physical Table: a amed set of rows ad colums that specifies the fields i each row of the table Deormalizatio: the process of splittig or combiig ormalized relatios ito physical tables based o affiity of use of rows ad fields Deormalizatio optimizes certai data processig activities at the expese of others. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 45
Desigig Physical Tables (Cot.) Three types of table partitioig: Rage partitioig: partitios are defied by ooverlappig rages of values for a specified attribute Hash partitioig: a table row is assiged to a partitio by a algorithm ad the maps the specified attribute value to a partitio Composite partitioig: combies rage ad hash partitioig by first segregatig data by rages o the desigated attribute, ad the withi each of these partitios 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 46
Desigig Physical Tables (Cot.) Various forms of deormalizatio, which ivolves combiig data from several ormalized tables, ca be doe. No hard-ad-fast rules for decidig Three commo situatios where deormalizatio may be used: Two etities with a oe-to-oe relatioship A may-to-may relatioship (associative etity) with okey attributes Referece data 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 47
File Orgaizatios File orgaizatio: a techique for physically arragig the records of a file Physical file: a amed set of table rows stored i a cotiguous sectio of secodary memory 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 48
File Orgaizatios (Cot.) 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 49
File Orgaizatios (Cot.) Sequetial file orgaizatio: a file orgaizatio i which rows i a file are stored i sequece accordig to a primary key value Hashed file orgaizatio: a file orgaizatio i which the address for each row is determied usig a algorithm Poiter: a field of data that ca be used to locate a related field or row of data 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 50
Arragig Table Rows Objectives for choosig file orgaizatio Fast data retrieval High throughput for processig trasactios Efficiet use of storage space Protectio from failures or data loss Miimizig eed for reorgaizatio Accommodatig growth Security from uauthorized use 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 51
Idexed File Orgaizatio Idexed file orgaizatio: a file orgaizatio i which rows are stored either sequetially or osequetially, ad a idex is created that allows software to locate idividual rows Idex: a table used to determie the locatio of rows i a file that satisfy some coditio Secodary keys: oe or a combiatio of fields for which more tha oe row may have the same combiatio of values 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 52
Idexed File Orgaizatio (Cot.) Mai disadvatages: Extra space required to store the idexes Extra time ecessary to access ad maitai idexes Mai advatage: Allows for both radom ad sequetial processig Guidelies for choosig idexes Specify a uique idex for the primary key of each table. Specify a idex for foreig keys. Specify a idex for okey fields that are refereced i qualificatio, sortig ad groupig commads for the purpose of retrievig data. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 53
Desigig Cotrols for Files Two of the goals of physical table desig are protectio from failure or data loss ad security from uauthorized use. These goals are achieved primarily by implemetig cotrols o each file. Two other importat types of cotrols address file backup ad security. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 54
Desigig Cotrols for Files (Cot.) Techiques for file restoratio iclude: Periodically makig a backup copy of a file. Storig a copy of each chage to a file i a trasactio log or audit trail. Storig a copy of each row before or after it is chaged. Meas of buildig data security ito a file iclude: Codig, or ecryptig, the data i the file. Requirig data file users to idetify themselves by eterig user ames ad passwords. Prohibitig users from directly maipulatig ay data i the file by forcig users to work with a copy (real or virtual). 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 55
Physical Database Desig for Hoosier Burger The followig decisios eed to be made: Decide to create oe or more fields for each attribute ad determie a data type for each field. For each field, decide if it is calculated; eeds to be coded or compressed; must have a default value or picture; or must have rage, referetial itegrity, or ull value cotrols. For each relatio, decide if it should be deormalized to achieve desired processig efficiecies. Choose a file orgaizatio for each physical file. Select suitable cotrols for each file ad the database. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 56
Electroic Commerce Applicatio: Desigig Databases Desigig databases for Pie Valley Furiture s WebStore Review the coceptual model (E-R diagram). Examie the lists of attributes for each etity. Complete the database desig. Share all desig iformatio with project team to be tured ito a workig database durig implemetatio. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 57
Summary I this chapter you leared how to: ü Cocisely defie each of the followig key database desig terms: relatio, primary key, ormalizatio, fuctioal depedecy, foreig key, referetial itegrity, field, data type, ull value, deormalizatio, file orgaizatio, idex, ad secodary key. ü Explai the role of desigig databases i the aalysis ad desig of a iformatio system. ü Trasform a etity-relatioship (E-R) diagram ito a equivalet set of well-structured (ormalized) relatios. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 58
Summary (Cot.) ü Merge ormalized relatios from separate user views ito a cosolidated set of well-structured relatios. ü Choose storage formats for fields i database tables. ü Traslate well-structured relatios ito efficiet database tables. ü Explai whe to use differet types of file orgaizatios to store computer files. ü Describe the purpose of idexes ad the importat cosideratios i selectig attributes to be idexed. 2014 Pearso Educatio, Ic. Publishig as Pretice Hall 59
Copyright 2014 Pearso Educatio, Ic. Publishig as Pretice Hall