Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transforming Data Models into Database Designs

Similar presentations


Presentation on theme: "Transforming Data Models into Database Designs"— Presentation transcript:

1 Transforming Data Models into Database Designs
Chapter 6 – Part 1 Transforming Data Models into Database Designs

2 Contents A. Computer Company Problem B. Solution

3 A. Computer Company Problem
ProgLtd is a company that places computer programmers at temporary jobs. They keep track on each programmer: the programmer's identification number, the programmer's last name, the programmer's first name, the programmer's rank (Junior, Senior ...), gender, his/her hourly rate and what languages the programmer knows. Beside, each programmer has been issued a badge which is used for enter their office. On each badge has following information: badge’s code, the programmer's identification number, issued date.

4 ProgLtd deals with clients who may require programmers who know a particular programming language and may request programmers who are experienced in such a programming. Once a programmer is assigned a temporary job, ProgLtd would like to keep track of when he/she started the job, the total number of hours he/she is expected to spend at job and the date he/she finished the job. That is in addition to the client name and phone number where the temp has been assigned. Let’s design DB diagram for above requirements

5 B. Solutions Logical Analysis Physical Analysis

6 1. Logical Analysis

7 2. Physical Analysis 2.1. Steps for Transforming a Data Model into a Database Design. 2.2. Create Table for Each Entity. 2.3. Create Relationships. 2.4. Design for Minimum Cardinality. 2.5. Physical Diagram.

8 2.1. Steps for Transforming a Data Model into a Database Design.

9 2.2. Create Table for Each Entity
Create a Table for Each Entity Select the Primary Key Specify Candidate (Alternate) Keys Specify Column Properties.

10 2.2.1. Create a Table for Each Entity

11 Select the Primary Key The ideal primary key is short, numeric and fixed Surrogate keys meet the ideal, but have no meaning to users

12 2.2.3. Specify Candidate (Alternate) Keys
The terms candidate key and alternate key are synonymous Candidate keys are alternate identifiers of unique rows in a table ERwin uses AKn.m notation, where n is the number of the alternate key, and m is the column number in that alternate key

13 2.2.4. Specify Column Properties
Specify Data Type. Specify Default Value. Specify Data Constraints.

14 Specify Data Type SQL Server Data Types Data Types on Table.

15 SQL Server Data Types

16 Data Types on Table

17 Specify Default Value A default value is the value supplied by the DBMS when a new row is created Example: Default value of PRO_Hourly_Rate is 15$

18 2.2.4.3. Specify Data Constraints
Data constraints are limitations on data values: Domain constraint - Column values must be in a given set of specific values Range constraint - Column values must be within a given range of values Intrarelation constraint – Column values are limited by comparison to values in other columns in the same table Interrelation constraint - Column values are limited by comparison to values in other columns in other tables [Referential integrity constraints on foreign keys]

19 2.3. Create Relationships :1 Entity Relationships :N Entity Relationships N:M Entity Relationships

20 2.3.1. 1:1 Entity Relationships
Place the key of one entity in the other entity as a foreign key: Either design will work – no parent, no child Minimum cardinality considerations may be important: O-M will require a different design that M-O, and one design will be very preferable.

21 2.3.2. 1:N Entity Relationships
Place the primary key of the table on the one side of the relationship into the table on the many side of the relationship as the foreign key The one side is the parent table and the many side is the child table, so “Place the key of the parent in the child”

22 2.3.3. N:M Entity Relationships
In an N:M strong entity relationship there is no place for the foreign key in either table The solution is to create an intersection table that stores data about the corresponding rows from each entity The intersection table consists only of the primary keys of each table which form a composite primary key Each table’s primary key becomes a foreign key linking back to that table

23

24 2.4. Design for Minimum Cardinality
Types of minimum cardinality Cascading Updates and Deletes Actions to Apply to Enforce Minimum Cardinality Implementing Actions.

25 2.4.1. Types of minimum cardinality
Relationships can have the following types of minimum cardinality: O-O : Parent optional and child optional M-O : Parent mandatory and child optional O-M : Parent optional and child mandatory M-M : Parent mandatory and child mandatory We will use the term action to mean a minimum cardinality enforcement action. No action needs to be taken for O-O relationships.

26 2.4.2. Cascading Updates and Deletes
A cascading update occurs when a change to the parent’s primary key is applied to the child’s foreign key. Surrogate keys never change and there is no need for cascading updates when using them. A cascading delete occurs when associated child rows are deleted along with the deletion of a parent row. For strong entities, generally do not cascade deletes. For weak entities, generally do cascade deletes.

27 2.4.3. Actions to Apply to Enforce Minimum Cardinality

28 Implementing Actions Implementing Actions for M-O Relationships Implementing Actions for O-M Relationships Implementing Actions for M-M Relationships What is trigger?

29 2.4.4.1. Implementing Actions for M-O Relationships
Make sure that: Every child has a parent. Operations never create orphans. The DBMS will enforce the action as long as: Referential integrity constraints are properly defined. The foreign key column is NOT NULL.

30 2.4.4.2. Implementing Actions for O-M Relationships
The DBMS does not provide much help. Triggers or other application code will need to be written.

31 2.4.4.3. Implementing Actions for M-M Relationships
The DBMS does not provide much help. Complicated and careful application programming will be needed.

32 What is trigger? Application programming uses SQL embedded in triggers, stored procedures, and other program code to accomplish specific tasks. A trigger is a stored program that is executed by the DBMS whenever a specified event occurs on a specified table or view. Triggers are used to enforce specific minimum cardinality enforcement actions not otherwise programmed into the DBMS.

33 2.5. Physical Diagram

34 ?


Download ppt "Transforming Data Models into Database Designs"

Similar presentations


Ads by Google