1. Trang chủ
  2. » Công Nghệ Thông Tin

Giáo trình niit quarter 2 virsion 2 rdd chương 2

42 299 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 42
Dung lượng 294,18 KB

Nội dung

LESSON: 2C COLLABORATE 2C.1 Relational Database Design Relational Database Design 2C.2 KNOWLEDGE BYTE Collaborate Knowledge Byte In this section, you will learn about the following: • Domains • Fourth Normal Form • Other Normal Forms ©NIIT Collaborate Lesson 2C / Slide of 25 In this section, you will learn about the following: „Domains „Fourth Normal Form „Other Normal Forms 2C.3 Relational Database Design Domains Collaborate Domains ©NIIT • A domain is a set of data values that are of the same type • Every value in an attribute must be drawn from the underlying domain However, every value in the domain may not appear in the table • Domains are primarily conceptual and no current RDBMS supports this concept in the complete sense • A relation is a collection of domains and consists of two parts, a heading and a body • A change in a relation implies that either a new domain is added to the collection of existing domains, or a domain that originally defined the relation no longer exists Collaborate Lesson 2C / Slide of 25 A domain is a set of data values that are of the same type In other words, a domain is a pool of values from which the actual values for an attribute are drawn For example, consider a domain CITIES that contains the names of all cities CUSTOMER and PRODUCT are two tables, both of which have an attribute that holds the names of cities Attribute CITY in the CUSTOMER table holds the names of cities where the customers are based Attribute CITY in the PRODUCT table holds the names of the cities where the products are manufactured Both these attributes draw their values from the CITIES domain Relational Database Design 2C.4 CUSTOMER DOMAIN: CITIES PRODUCT CITY New York Dallas Texas PRODUCT Dallas Miami San Francisco Las Vegas Texas New York Washington Disneyland Hollywood Philadelphia New York San Francisco Miami Domains and Attributes Every value in an attribute must be drawn from the underlying domain However, every value in the domain may not appear in the table In the above figure, some cities that are in the domain not exist in the attributes However, later, any of these values may exist in the attributes as they are valid values Domains are primarily conceptual and no current RDBMS supports this concept in the complete sense A relation is a collection of domains and consists of two parts, a heading and a body The heading part consists of a fixed set of attributes The body part consists of rows that may change with time The attributes of a relation are fixed If an attribute is added or an existing attribute is removed from a relation, the relation is no longer the same Such a change implies that either a new domain is added to the collection of existing domains, or a domain that originally defined the relation no longer exists 2C.5 Relational Database Design Fourth Normal Form Collaborate Fourth Normal Form ©NIIT • If a relation has many-to-many relationships with two or more relations, then the attributes of all the three or more relations cannot be depicted in the same relation • When you model such situations in a relational database, you will either have redundant data or use null values • A condition that requires duplication of values and thus enforces mutual independence of multivalued attributes is called multivalued dependency Collaborate Relational Database Design Lesson 2C / Slide of 25 2C.6 Collaborate Fourth Normal Form (Contd ) • You can use fourth normal form (4 NF) to remove multivalued dependencies • A table is in NF if it is in NF and has no multivalued dependencies • To apply NF, you need to put all multivalued attributes in individual tables containing the key to which the attribute values apply ©NIIT Collaborate Lesson 2C / Slide of 25 According to NF, a relation cannot have multivalued attributes This means that for one value of an attribute there cannot be multiple values of another attribute However, in real world, there might be situations where multivalued attributes are required For example, in a university, a faculty member is assigned multiple courses and committees Also, in a health insurance system, an employee has many dependents When you model such situations in a relational database, you will either have redundant data or null values For example, for the university database, the following figure depicts the FACULTY table that uses the above concept FACULTY FACULTYNAME 2C.7 COURSE COMMITTEE Chris 125 Admissions Chris 125 Examinations Chris 126 Admissions Relational Database Design FACULTYNAME COURSE COMMITTEE Chris 126 Examinations Chris 127 Admissions 127 Examinations Chris Table with Multivalued Dependency Such a condition that requires duplication of values and thus enforces mutual independence of multivalued attributes is called multivalued dependency Multivalued dependency is a constraint on tables like functional dependency It is clear that multivalued dependency requires duplication of data values Therefore, in normalization, you need to remove multivalued dependencies To this, you can use the fourth normal form (4 NF) A table is in NF if it is in NF and has no multivalued dependencies To apply NF, you need to put all multivalued attributes in individual tables containing the key to which the attribute values apply The above table can be normalized as follows: FAC-COURSE FACULTYNAME COURSE Chris 125 Chris 126 Chris 127 FAC-COMMITTEE FACULTYNAME COMMITTEE Chris Admissions Chris Examinations NF Tables Both the above tables are in NF because the multivalued attributes, COURSE and COMMITTEE, are now in tables by themselves The primary keys of each of the above tables consist of both the attributes present in the table This means that the primary key Relational Database Design 2C.8 of the FAC-COURSE table consists of FACULTY-NAME and COURSE The primary key of the FAC-COMMITTEE table consists of the FACULTY-NAME and COMMITTEE Other Normal Forms Collaborate Other Normal Forms ©NIIT • Some constraints like business rules result in the need for fifth normal form (5 NF) • For a table to be in NF, it has to be in NF and should abide by some business rules • The purpose of NF is to have tables that cannot be further decomposed • If the business rule does not exist, then there is no need of NF • In addition to NF, there is another normal form called the domain-key normal form (DKNF) • A table is in DKNF if every constraint on the table is a result of the definitions of domains and keys Collaborate Lesson 2C / Slide of 25 The normal forms NF, NF, and NF are the results of functional dependency and multivalued dependency There are some other constraints like business rules that result in the need for fifth normal form (5 NF) For a table to be in NF, it has to be in NF and should abide by some business rules The purpose of NF is to have tables that cannot be further decomposed Let us now understand NF with an example 2C.9 Relational Database Design Consider the following table: Department Subject Student Mathematics MA520 Ron Floyd Computer Science CS150 Nancy Drew Computer Science CS103 Charlie Burton Computer Science CS104 Ron Floyd Chemistry CH894 Chris Laurel Physics PH654 Mary Peterson This table indicates that the Computer Science department offers the subjects CS150, CS103, and CS104 These subjects are taken by different students Here, the business rule is that a subject cannot be taken by all the students and a student cannot take all the subjects The above table does not illustrate multivalued dependency because the columns SUBJECT and STUDENT are not independent Both these columns are related to each other and have important information in them Therefore, this table cannot be decomposed in the following two tables without losing information about the subjects taken by a student DEPT-SUB (DEPARTMENT, SUBJECT) DEPT-STUD (DEPARTMENT, STUDENT) However, we can decompose the above table in the following three tables without losing any information DEPT-SUB Department Subject Mathematics MA520 Computer Science CS150 Computer S i CS103 Relational Database Design 2C.10 Collaborate Challenge (Contd ) ©NIIT Which of the following rules should be followed to create a good database design? a Each table should have an identifier b Columns that accept NULLs should be avoided c Each table should store data for multiple types of entities d The repetition of values or columns should be avoided Collaborate Relational Database Design Lesson 2C / Slide 19 of 25 2C.28 Collaborate Challenge (Contd ) ©NIIT 2C.29 Match the following terms with their descriptions Specialization A It is a scientific method of breaking down complex table structures into simple table structures by using certain rules Normalization B It is the intentional introduction of redundancy in a table in order to improve performance Generalization C It is the result of taking a subset of a higher-level entity set to form a lower-level entity set Denormalization D It is the result of taking the union of two or more lower-level entity sets to produce a higher-level entity set Collaborate Lesson 2C / Slide 20 of 25 Relational Database Design Collaborate Challenge (Contd ) A relation that is in third normal form and has no multivalued dependencies is in 10 Consider the following statement of a manufacturing company: “A supplier ships certain parts A particular part is not necessarily shipped by only one supplier No supplier ships only a single part.” What type of relationship is this? Draw an E/R diagram to depict the relationship ©NIIT Collaborate Lesson 2C / Slide 21 of 25 The following statement has been extracted from a case presented by a manufacturer regarding the maintenance of their data: “A supplier ships certain parts” Identify the entities mentioned in this statement and their relationship Draw an E/R diagram depicting the relationship You have received a proposed table structure for the table Position After testing the table structure with some data, you find that there is a problem in inserting, deleting, and modifying data You see that the table structure could lead to inconsistency in data and is also occupying a lot of disk space Modify the given table structure to optimize data storage The table structure is as follows: Position cPositionCode vDescription iBudgetedStrength Relational Database Design 2C.30 siYear iCurrentStrength vSkill Sample data for the table Position is as shown below: cPosition Code vDescription iBudgeted Strength iCurrent Strength vSkill 0001 Sales Manager 100 82 Communication 0002 Marketing Manager 100 83 Presentation 0003 Financial Analyst 50 30 Team Leading 0004 Training Co-ord 20 15 Communication 0005 Database Analyst 10 Presentation 0006 Staff Accountant 20 18 Convincing 0007 Audit Manager 20 18 Planning 0008 Telephone Operator 20 18 Communication 0009 Office Clerk 20 18 Team Leading 0010 Legal Secretary 20 18 MS- Office 0011 Administrative Assistant 20 18 Interpersonal 0012 Senior Receptionist 20 18 Communication 0013 Consultant 20 18 Team Leading 0014 Maintenance Technician 20 18 Presentation 0015 Receptionist 21 18 Convincing 2C.31 Relational Database Design State whether true or false: Attributes may acquire further attributes and become entities Each time the salary slip for an employee is generated, the referral bonus (if present) has to be calculated and printed in the salary slip The following three tables are used for this query- MonthlySalary, Employee, and EmployeeReferrals The table structures are: Employee MonthlySalary EmployeeReferrals cEmployeeCode cEmployeeCode cEmployeeReferrralNo vFirstname mMonthlySalary cEmployeeCode vLastName dPayDate cCandidateCode cCandidateCode vAddress cCity cZip cCountryCode cPhone vQualification dBirthDate cSex cCurrentPosition cDesignation cEmailId cDepartmentCode cRegion imPhoto Relational Database Design 2C.32 Employee MonthlySalary EmployeeReferrals vSkill dJoiningDate dResignationDate cSocialSecurityNo However, since the table structures are large, it is necessary to improve the performance of this query by modifying the table structures Identify how to increase the performance of queries Which of the following are the consequences of redundancy? a b c d Update anomalies Improved database performance Inconsistencies Unnecessary utilization of extra disk space State whether true or false: The conceptual model design is concerned with the implementation and operation phases of the database Which of the following rules should be followed to create a good database design? a b c d Each table should have an identifier Columns that accept NULLs should be avoided Each table should store data for multiple types of entities The repetition of values or columns should be avoided Match the following terms with their descriptions Specialization A It is a scientific method of breaking down complex table structures into simple table structures by using certain rules Normalization B It is the intentional introduction of redundancy in a table in order to improve performance Generalization C It is the result of taking a subset of a higherlevel entity set to form a lower-level entity set Denormalization D It is the result of taking the union of two or more lower-level entity sets to produce a higherlevel entity set A relation that is in third normal form and has no multivalued dependencies is in 10 Consider the following statement of a manufacturing company: 2C.33 Relational Database Design “A supplier ships certain parts A particular part is not necessarily shipped by only one supplier No supplier ships only a single part.” What type of relationship is this? Draw an E/R diagram to depict the relationship Collaborate Solutions to Challenge Entities: SUPPLIER, PARTS Relationship: SHIP (or SHIPMENT) SHIP SUPPLIERS ©NIIT Collaborate Relational Database Design PARTS Lesson 2C / Slide 22 of 25 2C.34 Collaborate Solutions to Challenge (Contd ) Use normalization and break the table as follows: Position PositionCod e Description ©NIIT 2C.35 BudgetedPositi ons PositionCode PositionSki ll PositionCode BudgetedStrengt h CurrentStrength vSkill True Denormalize the tables by adding Referralbonus attribute in the MonthlySalary table Collaborate Lesson 2C / Slide 23 of 25 Relational Database Design Collaborate Solutions to Challenge (Contd ) ©NIIT Employee Monthly Salary CEmploye eCode VFirstNam e VLastNam e CCandidat eCode VAddress CCity CZip CCountryC ode CPhone VQualificat ion DBirthDat e CSex CCurrentP osition CDesignati on cEmploy eeCode mMonthl ySalary dPayDat e Referralb onus Employe eReferral s cEmpRefN o cEmploye eCode cCandidat eCode Collaborate Relational Database Design Lesson 2C / Slide 24 of 25 2C.36 Collaborate Solutions to Challenge (Contd ) 10 a, c, d False a, b, d 1-C, 2-A, 3-D, 4-B fourth normal form Many-to-many type SUPPLIER ©NIIT m m SHIP PARTS Collaborate Lesson 2C / Slide 25 of 25 INSTRUCTOR NOTES Solutions to Challenge Entities: SUPPLIER, PARTS Relationship: SHIP (or SHIPMENT) SUPPLIERS SHIP Use normalization and break the table as follows: 2C.37 Relational Database Design PARTS Position BudgetedPositions PositionSkill PositionCode PositionCode PositionCode Description BudgetedStrength vSkill CurrentStrength True Denormalize the tables by adding Referralbonus attribute in the MonthlySalary table Relational Database Design 2C.38 Employee MonthlySalary CEmployeeCode cEmployeeCode cEmpRefNo VFirstName mMonthlySalary cEmployeeCode VLastName dPayDate cCandidateCode CCandidateCode Referralbonus VAddress CCity CZip CCountryCode CPhone VQualification DBirthDate CSex CCurrentPosition CDesignation CEmailId CDepartmentCode cRegion imPhoto vSkill dJoiningDate dResignationDate 2C.39 EmployeeReferrals Relational Database Design cSocialSecurityNo a, c, d False a, b, d 1-C, 2-A, 3-D, 4-B fourth normal form 10 Many-to-many type SUPPLIER m m SHIP Relational Database Design PARTS 2C.40 COLLABORATIVE EXERCISES Group Discussion on Specialization and Generalization What are the differences between specialization and generalization? Hold the discussion on the following: „Higher-level entities „Lower-level entities „Attributes Let the students discuss the pros and cons of specialization and generalization Solution A higher-level entity might have some attributes that not apply to all instances of that entity This problem can be solved by using specialization Specialization is the result of taking a subset of a higher-level entity set to form a lower-level entity set Generalization is the opposite of specialization Some entities might have some common attributes A better option is to create a new higher-level entity to simplify multiple references Generalization is the result of taking the union of two or more lower-level entity sets to produce a higher-level entity set In generalization, every higher-level entity must also be a lower-level entity However, specialization does not have this constraint At the end, conclude that both specialization and generalization are useful in different situations in E/R diagrams Group Discussion on Denormalization Discuss why denormalization is necessary? What are the advantages and disadvantages of denormalization? Hold the discussion on the following: „Data consistency 2C.41 Relational Database Design „Query performance „Redundancy Let the students discuss the pros and cons of denormalization INSTRUCTOR NOTES Solution Normalization reduces the redundancy in a table This reduces the risk of inconsistent data However, sometimes, in normalization, multiple tables need to be joined to get a simple output This affects the speed of retrieval For example, in a complex database, a single query might need to refer to fifteen or more tables at a time In such cases, it is wiser to introduce a degree of redundancy either by introducing extra columns or extra tables The intentional introduction of redundancy in a table in order to improve query performance is called denormalization However, denormalization increases the risk of data inconsistency Therefore, the decision to denormalize will obviously result in a trade-off between performance and data consistency Denormalization also increases disk space utilization At the end, conclude that denormalization is not a desirable practice and should be considered as the last choice for improving query performance Relational Database Design 2C.42 [...]... Database Design Lesson 2C / Slide 13 of 25 2C .22 Collaborate Challenge (Contd ) The table structure is as follows: Position cPositionCode vDescription iBudgetedStrength siYear iCurrentStrength vSkill NIIT 2C .23 Collaborate Lesson 2C / Slide 14 of 25 Relational Database Design Collaborate Challenge (Contd ) Sample data for the table Position is as shown below: cPositionC ode 0001 00 02 0003 0004 0005 0006... 20 20 20 18 18 18 Team Leading MS- Office Interpersonal 20 20 20 18 18 18 Communication Team Leading Presentation 21 18 Convincing Collaborate Relational Database Design Communication Presentation Team Leading Communication Presentation Convincing Planning Communication Lesson 2C / Slide 15 of 25 2C .24 Collaborate Challenge (Contd ) 3 4 NIIT 2C .25 State whether true or false: Attributes may acquire... Convincing 0007 Audit Manager 20 18 Planning 0008 Telephone Operator 20 18 Communication 0009 Office Clerk 20 18 Team Leading 0010 Legal Secretary 20 18 MS- Office 0011 Administrative Assistant 20 18 Interpersonal 00 12 Senior Receptionist 20 18 Communication 0013 Consultant 20 18 Team Leading 0014 Maintenance Technician 20 18 Presentation 0015 Receptionist 21 18 Convincing 2C.31 Relational Database Design... Lesson 2C / Slide 22 of 25 2C.34 Collaborate Solutions to Challenge (Contd ) 2 Use normalization and break the table as follows: Position PositionCod e Description NIIT 2C.35 BudgetedPositi ons PositionCode PositionSki ll PositionCode BudgetedStrengt h CurrentStrength vSkill 3 True 4 Denormalize the tables by adding Referralbonus attribute in the MonthlySalary table Collaborate Lesson 2C / Slide 23 of 25 ... 0011 00 12 0013 0014 0015 NIIT vDescription Sales Manager Marketing Manager Financial Analyst Training Co-ord Database Analyst Staff Accountant Audit Manager Telephone Operator Office Clerk Legal Secretary Administrative Assistant Senior Receptionist Consultant Maintenance Technician Receptionist iBudgete dStrength 100 100 50 20 10 20 20 20 iCurrentStre ngth 82 83 30 15 8 18 18 18 vSkill 20 20 20 18... columns should be avoided Collaborate Relational Database Design Lesson 2C / Slide 19 of 25 2C .28 Collaborate Challenge (Contd ) 8 NIIT 2C .29 Match the following terms with their descriptions 1 Specialization A It is a scientific method of breaking down complex table structures into simple table structures by using certain rules 2 Normalization B It is the intentional introduction of redundancy in a... dResignationDat e cSocialSecurityN o mMonthlySalary dPayDate EmployeeReferr als cEmployeeReferrr alNo cEmployeeCode cCandidateCode Collaborate Relational Database Design Lesson 2C / Slide 17 of 25 2C .26 Collaborate Challenge (Contd ) 5 6 NIIT 2C .27 However, since the table structures are large, it is necessary to improve the performance of this query by modifying the table structures Identify how to increase... Design 2C.30 siYear iCurrentStrength vSkill Sample data for the table Position is as shown below: cPosition Code vDescription iBudgeted Strength iCurrent Strength vSkill 0001 Sales Manager 100 82 Communication 00 02 Marketing Manager 100 83 Presentation 0003 Financial Analyst 50 30 Team Leading 0004 Training Co-ord 20 15 Communication 0005 Database Analyst 10 8 Presentation 0006 Staff Accountant 20 18... result of the definitions of domains and keys Relational Database Design 2C. 12 FROM THE EXPERT’S DESK Collaborate From the Expert’s Desk • NIIT This section will introduce the following: • Best practices for the primary key • Tip on generalization • FAQs on data models, E/R diagrams, and normalization Collaborate Lesson 2C / Slide 6 of 25 In this section, you will learn about best practices for the primary... E/R diagram to depict the relationship NIIT Collaborate Lesson 2C / Slide 21 of 25 1 The following statement has been extracted from a case presented by a manufacturer regarding the maintenance of their data: “A supplier ships certain parts” Identify the entities mentioned in this statement and their relationship Draw an E/R diagram depicting the relationship 2 You have received a proposed table structure ... 100 100 50 20 10 20 20 20 iCurrentStre ngth 82 83 30 15 18 18 18 vSkill 20 20 20 18 18 18 Team Leading MS- Office Interpersonal 20 20 20 18 18 18 Communication Team Leading Presentation 21 18 Convincing... Database Design Lesson 2C / Slide 24 of 25 2C.36 Collaborate Solutions to Challenge (Contd ) 10 a, c, d False a, b, d 1-C, 2- A, 3-D, 4-B fourth normal form Many-to-many type SUPPLIER NIIT m m SHIP PARTS... Lesson 2C / Slide 13 of 25 2C .22 Collaborate Challenge (Contd ) The table structure is as follows: Position cPositionCode vDescription iBudgetedStrength siYear iCurrentStrength vSkill NIIT 2C .23

Ngày đăng: 04/12/2015, 06:33

TỪ KHÓA LIÊN QUAN

w