Systems Analysis and Design in a 1212 12 Changing World, Fourth Edition Learning Objectives Describe the differences and similarities between relational and object-oriented database management systems
Design a relational database schema based on Chapter 12: an entity-relationship diagram Designing Databases Design an object database schema based on a class diagram
Systems Analysis and Design in a Changing World, 4th Edition 2
12 12 Learning Objectives ( continued ) Overview
Design a relational schema to implement a hybrid This chapter describes design of relational and object-relational database OO data models Developers transform conceptual data models into detailed database models Describe the different architectural models for distributed databases Entity-relationship diagrams (ERDs) for traditional analysis Class diagrams for object-oriented (OO) analysis Detailed database models are implemented with database management system (DBMS)
Systems Analysis and Design in a Changing World, 4th Edition 3 Systems Analysis and Design in a Changing World, 4th Edition 4 12 12 Databases and Database Databases and Database Management Systems Management Systems (Cont.) Databases (DB) – integrated collections of stored The database (DB) consists of two related data that are centrally managed and controlled information store:
o Entity or class attribute( eg. names, prices ). o The physical data store: used by DBMS to store the raw bits and bytes of a database. o Relationships among the entities or classes ( eg. which orders belong to which customers) . o The schema: description of structure, content, and access controls of a physical data store or DB. o Stores descriptive information about data, such as field names, restrictions on allowed data and Database management system (DBMS) – system access control to sensitive information. software that manages and controls access to database (eg. Microsoft access, Oracle, DM2)
Systems Analysis and Design in a Changing World, 4th Edition 5 Systems Analysis and Design in a Changing World, 4th Edition 6
12 12 Components of a DB and DBMS Important DBMS Capabilities
Simultaneous access by multiple users and applications.
Access to data without writing application programs (via a query language).
Organizational data management with uniform access and content controls
Systems Analysis and Design in a Changing World, 4th Edition 7 Systems Analysis and Design in a Changing World, 4th Edition 8 12 12 Database Models Relational Databases
Impacted by technology changes since 1960s Relational database management system (RDBMS): organizes data into tables or relations Model types Tables are two dimensional data structures Hierarchical Tuples – rows or records Network Fields – columns or attributes Relational Object-oriented Tables have primary key field(s) that can be used to identify unique row of relational database table. Most current systems use relational or object- oriented data models Keys: A field that contains a value that is unique within each row of a RDBMS.
Systems Analysis and Design in a Changing World, 4th Edition 9 Systems Analysis and Design in a Changing World, 4th Edition 10
12 12 Partial Display of Relational Database Designing Relational Databases Table (Figure 12-2) Create table for each entity type Choose or invent primary key for each table Add foreign keys to represent one-to-many relationships Create new tables to represent many-to-many relationships Define referential integrity constraints Evaluate schema quality and make necessary improvements Choose appropriate data types and value restrictions (if necessary) for each field Systems Analysis and Design in a Changing World, 4th Edition 11 Systems Analysis and Design in a Changing World, 4th Edition 12 12 12
RMO Entity-Relationship Diagram (Figure 12-5) Entity Tables with Primary Keys (Figure 12-7)
Systems Analysis and Design in a Changing World, 4th Edition 13 Systems Analysis and Design in a Changing World, 4th Edition 14
12 12 Represent One-to-Many Relationships by Representing Relationships Adding Foreign Keys (in italics) (Figure 12-8) Relational databases use foreign keys to represent relationships One-to-many relationship Add primary key field of “one” entity type as foreign key in table that represents “many” entity type Many-to-many relationship Use the primary key field(s) of both entity types Use (or create) an associative entity table to represent relationship (Figure 12-9 in text book)
Systems Analysis and Design in a Changing World, 4th Edition 15 Systems Analysis and Design in a Changing World, 4th Edition 16 12 12 Relationship Between Data in Two Tables Enforcing Referential Integrity
Referential Integrity: describes a consistent state among foreign key and primary key( eg. An order must be from a customer).
Every foreign key value also exists as a primary key value
DBMS enforces referential integrity automatically after schema designer identifies primary and
Systems Analysis and Design in a Changing World, 4th Edition 17 foreign keys 18
12 12 DBMS Referential Integrity Enforcement Evaluating Schema Quality
When rows containing foreign keys are created High-quality data model has
DBMS ensures that value also exists as a primary Uniqueness of table rows and primary keys key in a related table Ease of implementing future data model changes When row is deleted (flexibility and maintainability) DBMS ensures no foreign keys in related tables have same value as primary key of deleted row Lack of redundant data (database normalization ) When primary key value is changed Database design is not objective or quantitatively DBMS ensures no foreign key values in related measured; it is experience and judgment based tables contain the same value
Systems Analysis and Design in a Changing World, 4th Edition 19 Systems Analysis and Design in a Changing World, 4th Edition 20 Database Normalization 12 12 Decomposition of 1NF Table into 2NF Tables Normalization: Ensures relational database schema quality by minimizing data redundancy. Normal forms minimize data redundancy First normal form (1NF) – no repeating fields or groups of fields. IssueDate is Functional dependency – one-to-one relationship between determined by CatalogID alone, the values of two fields. not by both CatalogID and The relationship is formally stated as follows: ProductID Field A is functionally depend on field B if for each value of B there is only one corresponding value of A 2NF – in 1NF and if each non-key element is functionally dependent on entire primary key 3NF – in 2NF and if no non-key element is functionally dependent on any other non-key element 21 Systems Analysis and Design in a Changing World, 4th Edition 22
12 12 Object-Oriented Databases Conversion of 2NF Table into 3NF Tables Direct extension of OO design and programming paradigm ODBMS stores data as objects or class instances and to interface with OO programming languages ZipCode determines the Direct support for method storage, inheritance, value for State, and ZipCode is nested objects, object linking, and programmer- not the key to the table defined data types Object Definition Language (ODL) Standard object database description language for describing structure and content of an object database Systems Analysis and Design in a Changing World, 4th Edition 23 24 12 12 Representing Classes Designing Object Databases There are two types of classes for purpose of DM Determine which classes require persistent storage Transient classes Objects exist only during lifetime of program or Define persistent classes process Examples: view layer window, pop-up menu Represent relationships among persistent Persistent classes classes Objects not destroyed when program or process ceases execution. State must be remembered. Choose appropriate data types and value restrictions (if necessary) for each field Exist independently of program or process Examples: problem domain( customer information, employee information). Systems Analysis and Design in a Changing World, 4th Edition 25 26
12 12 Representing Relationships Representing Relationships ( continued )
Object identifiers Advantages include Used to identify objects uniquely ODBMS assumes responsibility for determining connection among objects Physical storage address or reference ODBMS assumes responsibility for maintaining Relate objects of one class to another referential integrity ODBMS uses attributes containing object Type of relationships identifiers to find objects that are related to other objects 1:1, 1:M, M:M (one-to-one, one-to-many, many-to- many) Keyword relationship can be used to declare relationships between classes Association class used with M:M
Systems Analysis and Design in a Changing World, 4th Edition 27 Systems Analysis and Design in a Changing World, 4th Edition 28 12 One-to-One Relationship Represented 12 with Attributes Containing Object RMO Domain Identifiers Model Class Diagram
(Figure 12-15)
Systems Analysis and Design in a Changing World, 4th Edition 29 Systems Analysis and Design in a Changing World, 4th Edition 30
12 12 One-to-Many Relationship Between One-to-Many Relationship Represented with Attributes Containing Object Identifiers Customer and Order Classes
Systems Analysis and Design in a Changing World, 4th Edition 31 Systems Analysis and Design in a Changing World, 4th Edition 32 12 12 Many-to-Many Relationship between Generalization Hierarchy within Employee and Project Classes (Figure 12-19) the RMO Class Diagram (Figure 12-21)
Systems Analysis and Design in a Changing World, 4th Edition 33 Systems Analysis and Design in a Changing World, 4th Edition 34
12 12 Hybrid Object-Relational Database Design Classes and Attributes
Designers store classes and object attributes in RDBMS ( hybrid DBMS ) used to store object RDBMS by table definition attributes and relationships For new system :relational schema can be designed Design complete relational schema and based on class diagram simultaneously design equivalent set of classes Table is created for each class Mismatches between relational data and OO Fields of each table same as attributes of class Class methods cannot be directly stored or Row holds attribute values of single object automatically executed Key field is chosen for each table Relationships are restricted compared to ODBMS อย่าลืมทํา EER Mapping (Class Table) ODBMS can represent wider range of data types Step 8 (เลือก Optionไหน 8A-8C) Step 1-7 Systems Analysis and Design in a Changing World, 4th Edition 35 Systems Analysis and Design in a Changing World, 4th Edition 36 12 12 Views of Stored Data Relationships
Relationships are represented with foreign keys Foreign key values serve same purpose as object identifiers in ODBMS 1:M relationship – add primary key field of class on “one” side of the relationship to table representing class on “many” side M:M relationship – create new table that contains primary key fields of related class tables and attributes of the relationship itself
Systems Analysis and Design in a Changing World, 4th Edition 37 Systems Analysis and Design in a Changing World, 4th Edition 38
12 12 Data Access Classes
OO design based on a three-layer architecture Interaction Among a Data access classes are implementation bridge Domain Class, between data stored in program objects and data a Data Access in relational database Class, and the DBMS
Methods add, update, find, and delete fields and (Figure 12-25) rows in table or tables that represent the class
Methods encapsulate logic needed to copy data values from problem domain class to database and vice versa
Systems Analysis and Design in a Changing World, 4th Edition 39 Systems Analysis and Design in a Changing World, 4th Edition 40 12 12 Data Types Relational DBMS Data Types
Storage format and allowable content of program Designer must choose appropriate data type for variable, object state variable, or database field each field in relational database schema or attribute Choice for many fields is straightforward Primitive data types – directly implemented Names and addresses use a set of fixed- or variable-length character arrays Memory address (pointer), Boolean, integer, and so on Inventory quantities can use integers Item prices can use real numbers Complex data types – user-defined Dates, times, audio streams, video images, URLs Complex data types (DATE, LONG, LONGRAW)
Systems Analysis and Design in a Changing World, 4th Edition 41 Systems Analysis and Design in a Changing World, 4th Edition 42
12 12 Subset of Oracle RDBMS Data Types Object DBMS Data Types
Use set of primitive and complex data types comparable to RDBMS data types Schema designer can create new data types and associated constraints Classes are complex user-defined data types that combine traditional concept of data with processes (methods) to manipulate data Flexibility to define new data types is one reason that OO tools are widely used
Systems Analysis and Design in a Changing World, 4th Edition 43 Systems Analysis and Design in a Changing World, 4th Edition 44 12 12 Single Database Server Architecture Distributed Databases (Figure 12-27) Rare for all organizational data to be stored in a single database in one location
Different information systems in an organization are developed at different times
Parts of an organization’s data may be owned and managed by different units
System performance is improved when data is near primary applications
Systems Analysis and Design in a Changing World, 4th Edition 45 Systems Analysis and Design in a Changing World, 4th Edition 46
Single Database Server Architecture 12 12 Replicated Database Server Architecture (Cont.) (Figure 12-28) Primary Advantages: Simplicity, because there are only one server to manage. Primary Disadvantages: o Server failure o Possible load of the server o No back up capabilities in the event of server failure. Poorly suited to applications that must be available on 24/7
Systems Analysis and Design in a Changing World, 4th Edition 47 Systems Analysis and Design in a Changing World, 4th Edition 48 12 12 Partitioning Database Schema Replicated Database Server Architecture into Client Access Subsets Designers can eliminate delay in accessing distance database server. More fault tolerance. Load balancing. Primary Disadvantage: o Data inconsistency Database Synchronization: The process of ensuring consistency among two or more database copies.
Systems Analysis and Design in a Changing World, 4th Edition 49 Systems Analysis and Design in a Changing World, 4th Edition 50
12 12 Federated Database Partitioned Database Server Architecture Server Architecture
Systems Analysis and Design in a Changing World, 4th Edition 51 Systems Analysis and Design in a Changing World, 4th Edition 52 12 12 Single-Server Database RMO Distributed Database Architecture Server Architecture for RMO Starting point for design was information about data needs of geographically dispersed users
RMO gathered information during analysis phase
RMO decided to manage database using Park City data center mainframe
RMO is evaluating single-server vs. replicated and partitioned database server architectures
Information on network traffic and costs needed
Systems Analysis and Design in a Changing World, 4th Edition 53 Systems Analysis and Design in a Changing World, 4th Edition 54
12 12 Replicated and Partitioned Database Summary Modern information systems store data in database and access and Server Architecture for RMO manage data using DBMS Relational DBMS is commonly used Object DBMS is increasing in popularity Key activity of systems design is developing relational or object database schema Relational database is collection of data stored in tables and is developed from entity-relationship diagram Object database stores data as collection of related objects and is developed from class diagram Objects can also be stored in RDBMS RDBMS cannot store methods RDBMS cannot directly represent inheritance Medium and larger information systems typically use multiple databases or database servers in various geographic locations Systems Analysis and Design in a Changing World, 4th Edition 55 Systems Analysis and Design in a Changing World, 4th Edition 56