CMP-3440 Database Systems

Similar documents
Steps in normalisation. Steps in normalisation 7/15/2014

Functional Dependencies and Normalization for Relational Databases Design & Analysis of Database Systems

8) A top-to-bottom relationship among the items in a database is established by a

Dr. Anis Koubaa. Advanced Databases SE487. Prince Sultan University

Relational Database design. Slides By: Shree Jaswal

Lecture5 Functional Dependencies and Normalization for Relational Databases

The strategy for achieving a good design is to decompose a badly designed relation appropriately.

Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 10-2

Chapter 14 Outline. Normalization for Relational Databases: Outline. Chapter 14: Basics of Functional Dependencies and

MODULE: 3 FUNCTIONAL DEPENDENCIES

Normalisation. Connolly, Ch. 13

IS 263 Database Concepts

FUNCTIONAL DEPENDENCIES CHAPTER , 15.5 (6/E) CHAPTER , 10.5 (5/E)

Informal Design Guidelines for Relational Databases

Functional Dependencies & Normalization for Relational DBs. Truong Tuan Anh CSE-HCMUT

Chapter 10. Chapter Outline. Chapter Outline. Functional Dependencies and Normalization for Relational Databases

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 6 Normalization of Database Tables

Chapter 14. Database Design Theory: Introduction to Normalization Using Functional and Multivalued Dependencies

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

Unit IV. S_id S_Name S_Address Subject_opted

CS 2451 Database Systems: Database and Schema Design

Guideline 1: Semantic of the relation attributes Do not mix attributes from distinct real world. example

Functional Dependencies and. Databases. 1 Informal Design Guidelines for Relational Databases. 4 General Normal Form Definitions (For Multiple Keys)

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

Normalisation. Normalisation. Normalisation

UNIT 3 DATABASE DESIGN

COSC Dr. Ramon Lawrence. Emp Relation

ECE 650 Systems Programming & Engineering. Spring 2018

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Data about data is database Select correct option: True False Partially True None of the Above

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

4. Entity Relationship Model

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database?

DATABASE MANAGEMENT SYSTEMS

Database design process

Unit- III (Functional dependencies and Normalization, Relational Data Model and Relational Algebra)

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

DC62 DATABASE MANAGEMENT SYSTEMS DEC 2013

In Chapters 3 through 6, we presented various aspects

Transforming ER to Relational Schema

Database Design Theory and Normalization. CS 377: Database Systems

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

SQL STRUCTURED QUERY LANGUAGE

DATABASE MANAGEMENT SYSTEMS

Draw A Relational Schema And Diagram The Functional Dependencies In The Relation >>>CLICK HERE<<<

FIT1004 Database Topic 6: Normalisation

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 4 - Schema Normalization

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

Detailed Data Modelling. Detailed Data Modelling. Detailed Data Modelling. Identifying Attributes. Attributes

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

CT13 DATABASE MANAGEMENT SYSTEMS DEC 2015

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

SQL Introduction. CS 377: Database Systems

Chapter 3. The Relational database design

SVY227: Databases for GIS

Data Definition Language (DDL)

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Slides by: Ms. Shree Jaswal

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 9 Normalizing Database Designs

Functional Dependencies CS 1270

SQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99

Relational Database Systems Part 01. Karine Reis Ferreira

Fundamentals, Design, and Implementation, 9/e Copyright 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e by David M.

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Database Management System 9

Learning outcomes. On successful completion of this unit you will: 1. Understand data models and database technologies.

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

Relational Design 1 / 34

Relational Database Components

Database Foundations. 3-9 Validating Data Using Normalization. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

RELATIONAL DATA MODEL

COSC Assignment 2

Relational Design: Characteristics of Well-designed DB

Relational Model. CS 377: Database Systems

B.C.A DATA BASE MANAGEMENT SYSTEM MODULE SPECIFICATION SHEET. Course Outline

- Database: Shared collection of logically related data and a description of it, designed to meet the information needs of an organization.

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

Solved MCQ on fundamental of DBMS. Set-1

QUESTION BANK. SUBJECT CODE / Name: CS2255 DATABASE MANAGEMENT SYSTEM UNIT III. PART -A (2 Marks)

CS 377 Database Systems

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

Detailed Data Modelling: Attribute Collection and Normalisation of Data

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Database Tables and Normalization

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

PESIT Bangalore South Campus

6 February 2014 CSE-3421M Test #1 w/ answers p. 1 of 14. CSE-3421M Test #1. Design

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Lecture 07. Spring 2018 Borough of Manhattan Community College

The Relational Model

SQL Interview Questions

CS403 - Database Management Systems Short Notes

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2009 Lecture 3 - Schema Normalization

Transcription:

CMP-3440 Database Systems Logical Design Lecture 03 zain 1

Database Design Process Application 1 Conceptual requirements Application 1 External Model Application 2 Application 3 Application 4 External Model External Model External Model Application 2 Conceptual requirements Application 3 Conceptual requirements Conceptual Model Logical Model Internal Model Application 4 Conceptual requirements

Logical Model: Mapping to a Relational Model Each entity in the ER Diagram becomes a relation. A properly normalized ER diagram will indicate where intersection relations for many-to-many mappings are needed. Relationships are indicated by common columns (or domains) in tables that are related. 3

Data Dependencies Functional Dependency: Given a relation R(A,B,C,D) where A, B, C, D are attributes Functional Dependencies A -> BCD, BC -> D Full Functional Dependency: A -> B,C,D Partial Dependency: (A,B,C,D,E,F) AB -> C,D,EF A -> C,E and B -> D,F Transitive Dependency: (A,B,C,D) A -> B B - > C C -> D 4

Normalization Normalization theory is based on the observation that relations with certain properties are more effective in inserting, updating and deleting data than other sets of relations containing the same data Normalization is a multi-step process beginning with an unnormalized relation 5

Normal Forms First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) Boyce-Codd Normal Form (BCNF) 6

Normal Forms No transitive dependency between nonkey attributes All determinants are candidate keys - Single multivalued dependency Boyce- Codd and Higher Functional dependency of nonkey attributes on the primary key - Atomic values only Full Functional dependency of nonkey attributes on the primary key 7

Unnormalised Form (UNF) A table that contains one or more repeating groups. To create an unnormalized table: Transform data from information source (e.g. form) into table format with columns and rows. 8

First Normal Form To move to First Normal Form a relation must contain only atomic values at each row and column. A relation in which intersection of each row and column contains one and only one value. Disallows composite attributes, multivalued attributes & nested relations UNF to 1NF Nominate an attribute or group of attributes to act as the key for the unnormalized table. Identify repeating group(s) in unnormalized table which repeats for the key attribute(s). 9

UNF to 1NF Remove repeating group by: Entering appropriate data into the empty columns of rows containing repeating data ( flattening the table). 10

Second Normal Form A relation is said to be in Second Normal Form when every nonkey attribute is fully functionally dependent on the primary key. That is, every nonkey attribute needs the full primary key for unique identification Identify primary key for the 1NF relation. Identify functional dependencies in the relation. If partial dependencies exist on the primary key remove them by placing them in a new relation along with copy of their determinant. 11

2NF Example EMP_PROJ SSN PNUMBER HOURS ENAME PNAME PLOCATION SSN, PNUMBER -> HOURS SSN -> ENAME PNUMBER -> PNAME, PLOCATION 12

Third Normal Form A relation is said to be in Third Normal Form if there is no transitive functional dependency between nonkey attributes When one nonkey attribute can be determined with one or more nonkey attributes there is said to be a transitive functional dependency. 3NF - A relation that is in 1NF and 2NF and in which no nonprimary-key attribute is transitively dependent on the primary key. 3NF - All non-prime attributes are fully & directly dependent on the PK. 13

3NF EMP_PROJ SSN ENAME BDATE ADDRESS DNUMBER DNAME DMGRSSN SSN -> ENAME, BDATE, ADDRESS, DNUMBER DNUMBER -> DNAME, DMGRSSN SSN ENAME BDATE ADDRESS DNUMBER DNUMBER DNAME DMGRSSN 14

Boyce-Codd Normal Form Most 3NF relations are also BCNF relations. A 3NF relation is NOT in BCNF if: Candidate keys in the relation are composite keys (they are not single attributes) There is more than one candidate key in the relation, and A relation is in BCNF if & only if every determinant is a candidate key. 15

BCNF Example 2 composite candidate keys: FD1:{Client, Subject} Staff FD2:{Client & Staff} Subject Client Subject Staff Client Staff Subject These candidate keys are overlapping on Client. Staff is a determinate but not a candidate key 16

Data Integrity Ensuring the integrity of the organization s databases is a key component of the DBA s job. A database is of little use if the data it contains is inaccurate or if it cannot be accessed due to integrity problems. The DBA has many tools at his disposal to ensure data integrity. 17

Entity Integrity That each occurrence of an entity must be uniquely identifiable. Although most DBMSs do not FORCE the creation of a primary key for each table, it is a tenet of the Relational Model. Enforce entity integrity by creating a PK for each table in the database. A primary key constraint can consist of one or more columns from the same table that are unique within the table. A table can have only one primary key constraint, which cannot contain nulls. 18

Uniqueness A unique constraint is similar to a primary key constraint. However, each table can have many unique constraints. Unique constraints cannot be used to support referential constraints. The values stored in the column, or combination of columns, must but unique within the table. That is, no other row can contain the same value. A unique constraint most likely requires a unique index to enforce. 19

Data Types Data type and data length are the most fundamental integrity constraints applied to data in the database. DBAs must choose data types wisely. The DBMS will automatically ensure that only the correct type of data is stored in that column. Choose the data type that most closely matches the domain of values for the column. For example, a numeric column should be defined as one of the numeric data types: integer, decimal, or floating point. If you specify a character data type for a column that will contain numeric data the DBMS cannot automatically enforce the integrity of the data. 20

Default Values Each column can be assigned a default value that will be used if subsequent INSERTs do not provide a value. Each column can have only one default value. The column s data type, length, and property must be able to support the default value specified. The default may be null, but only if the column is created as a nullable column. 21

CHECK Constraints A check constraint is a DBMS-defined restriction placed on the data values that can be stored in a column or columns. The expression is explicitly defined in the table DDL and is formulated in much the same way that SQL WHERE clauses are formulated. Any attempt to modify the column data (INSERT or UPDATE) causes the expression to be evaluated. If the modification conforms to the expression, the modification is permitted to proceed. If not, the statement will fail with a constraint violation. 22

CHECK Constraints Example 23

Referential Integrity Referential Integrity (RI) is a method for ensuring the correctness of data. The identification of the primary and foreign keys that constitute a relationship between tables is a component of defining referential integrity. RI also requires the definition of rules that dictate how modification of data stored in columns involved in the relationship can be accomplished. 24

RI: Parent / Child For any given referential constraint, the parent table is the table that contains the primary key, and the child table is the table that contains the foreign key. The parent table in the employed-by relationship is the DEPT table. The child table is the EMP table.

RI Rules Three types of rules can be attached to each referential constraint: INSERT rule UPDATE rule DELETE rule

INSERT Rules The INSERT rule indicates what will happen if you attempt to insert a value into a foreign key column without a corresponding primary key value in the parent table. There are two aspects to the RI INSERT rule: 1. It is never permissible to insert a row into a dependent table with a foreign key value that does not correspond to a primary key value. This is known as the restrict-insert rule. 2. Whether actual values must be specified instead of nulls.

UPDATE Rule The UPDATE rule controls updates such that a foreign key value cannot be updated to a value that does not correspond to a primary key value in the parent table. There are, however, two ways to view the update rule: Foreign key perspective. Primary key perspective.

UPDATE Rule: FK Perspective Once you have assigned a foreign key to a row, either at insertion or afterward, you must decide whether that value can be changed. This is determined by looking at the business definition of the relationship and the tables it connects. If you permit a foreign key value to be updated, the new value must either be equal to a primary key value currently in the parent table or be null.

UPDATE Rule: PK Perspective If a primary key value is updated, three options exist for handling foreign key values: Restricted UPDATE. The modification of the primary key column(s) is not allowed if foreign key values exist. Neutralizing UPDATE. All foreign key values equal to the primary key value(s) being modified are set to null. Of course, neutralizing UPDATE requires that nulls be permitted on the foreign key column(s). Cascading UPDATE. All foreign key columns with a value equal to the primary key value(s) being modified are modified as well.

DELETE Rule Similar to the primary key perspective of the update rule, three options exist when deleting a row from a parent table: Restricted DELETE. The deletion of the primary key row is not allowed if a foreign key value exists. Neutralizing DELETE. All foreign key values equal to the primary key value of the row being deleted are set to null. Cascading DELETE. All foreign key rows with a value equal to the primary key of the row about to be deleted are deleted as well.