Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB



Similar documents
Fundamentals of Database Design

Introduction to normalization. Introduction to normalization

Lecture 6. SQL, Logical DB Design

SQL AND DATA. What is SQL? SQL (pronounced sequel) is an acronym for Structured Query Language, CHAPTER OBJECTIVES

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

DATABASE INTRODUCTION

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

There are five fields or columns, with names and types as shown above.

The Entity-Relationship Model

DATABASE SYSTEMS. Chapter 7 Normalisation

DATABASE NORMALIZATION

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

Exercise 1: Relational Model

Foundations of Information Management

Fundamentals of Database System

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

Databases and BigData

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

Entity - Relationship Modelling

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Data Modeling: Part 1. Entity Relationship (ER) Model

A brief overview of developing a conceptual data model as the first step in creating a relational database.

Benefits of Normalisation in a Data Base - Part 1

SQL, PL/SQL FALL Semester 2013

Normalization in Database Design

Relational Database Concepts

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

IT2305 Database Systems I (Compulsory)

2. Basic Relational Data Model

IT2304: Database Systems 1 (DBS 1)


Lecture Notes INFORMATION RESOURCES

Chapter 9: Normalization

C HAPTER 4 INTRODUCTION. Relational Databases FILE VS. DATABASES FILE VS. DATABASES

1 Class Diagrams and Entity Relationship Diagrams (ERD)

ISM 318: Database Systems. Objectives. Database. Dr. Hamid R. Nemati

Normalization. CIS 3730 Designing and Managing Data. J.G. Zheng Fall 2010

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Topic 5.1: Database Tables and Normalization

Chapter 6. Database Tables & Normalization. The Need for Normalization. Database Tables & Normalization

Designing Databases. Introduction

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

7.1 The Information system

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

BCA. Database Management System

Entity Relationship Diagram

7. Databases and Database Management Systems

1. INTRODUCTION TO RDBMS

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

The Relational Model. Why Study the Relational Model?


Displaying Data from Multiple Tables. Chapter 4

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Database Management. Technology Briefing. Modern organizations are said to be drowning in data but starving for information p.

How To Write A Diagram

Module 5: Normalization of database tables

Chapter 1. Writing Basic. SQL Statements

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

Modern Systems Analysis and Design

EECS 647: Introduction to Database Systems

Part 6. Normalization

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

DATABASE DESIGN: NORMALIZATION NOTE & EXERCISES (Up to 3NF)

3. Relational Model and Relational Algebra

SQL Introduction Chapter 7, sections 1 & 4. Introduction to SQL. Introduction to SQL. Introduction to SQL

Chapter 2. Data Model. Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel

2. Conceptual Modeling using the Entity-Relationship Model

Data Modeling Basics

ECS 165A: Introduction to Database Systems

Review: Participation Constraints

Databases What the Specification Says

Information Systems Analysis and Design CSC John Mylopoulos Database Design Information Systems Analysis and Design CSC340

LOGICAL DATABASE DESIGN

Normalization. Functional Dependence. Normalization. Normalization. GIS Applications. Spring 2011

Database Design. Adrienne Watt. Port Moody

Foundations of Information Management

CS143 Notes: Normalization Theory

IV. The (Extended) Entity-Relationship Model

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

Study Notes for DB Design and Management Exam 1 (Chapters 1-2-3) record A collection of related (logically connected) fields.

Files. Files. Files. Files. Files. File Organisation. What s it all about? What s in a file?

The process of database development. Logical model: relational DBMS. Relation

Higher National Unit specification: general information. Relational Database Management Systems

Course: CSC 222 Database Design and Management I (3 credits Compulsory)

EXTENDED LEARNING MODULE A

COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

Oracle Database 10g: Introduction to SQL

Normalization. Reduces the liklihood of anomolies

TIM 50 - Business Information Systems

Normalization of Database

Tutorial on Relational Database Design

Instant SQL Programming

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. COURSE CURRICULUM COURSE TITLE: DATABASE MANAGEMENT (Code: ) Information Technology

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University

Transcription:

Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Outline Database concepts Conceptual Design Logical Design Communicating with the RDBMS 2

Some concepts Database: an integrated collection of logically related data. Data: known facts that can be stored (text, graphics, images, ). Database management system (DBMS): system that stores, retrieves, and modifies data in the database. 3

Some concepts Database schema: a collection of database objects. Relational database: Collection of twodimensional tables. 4

Database systems Software Application Programs DBMS What to get How to get interact develop maintain End User Application Programmers Database Administrators Data Database design Users Database Designers 5

Why is design important? Why do I need a database? To store data and be able to process it to produce information! Define how to store the data. 6

Design goals Store information without unnecessary redundancy Retrieve information easily and accurately Be scalable for data and interfaces 7

Phases Conceptual Design Produces the initial model of the real world in a conceptual model Logical Design Consists of transforming this schema into the data model supported by the DBMS Physical Design (not covered) Aims at improving the performance of the final system 8

Conceptual Design Process of constructing a model of the information used in an enterprise. Is a conceptual representation of the data structures. Is independent of all physical considerations. 9

Conceptual Design Input: database requirements Output: conceptual model It should be simple enough to communicate with the end user It should be detailed enough to create the physical structure 10

Entity Relationship Model The Entity-Relationship model (ER) is most common conceptual model for database design Describes the data in a system and how data is related Describes data as entities, attributes, and relationships 11

EMPLOYEE Entities Concepts (abstract or real) about which information is collected Ex: employee, region, building, project, registration Entity Instance: entity individual occurrence 12

Attributes EMPLOYEE # id * name o age Properties which describe the entities Ex: Name (attribute of entity employee) Identify, describe, classify or quantify an entity An attribute instance is a value John Smith is a value of attribute Name Characteristics: optionality Required or optional 13

DEPARTMENT EMPLOYEE Relationship # id * name o location composed of assigned to # id * name o age Associations between entities Ex: employees are assigned to projects departments manage projects Degree: number of entities associated with a relationship (most common are binary) Cardinality: indicates the maximum possible number of entity occurrences Existence: indicates the minimum number of entity occurrences 14

Relationship cardinality one-to-one (1:1) A manager is head of a department one-to-many (1:N) A department has many employees Each employee is assigned to one department many-to-many (M:N) Employees are assigned to many projects Projects have assigned several employees 15

Relationship existence Mandatory (must be) Every project must be managed by a department Optional (may be) Employees may be assigned to work on projects 16

ER Diagram Notation Entity Relationship Attribute DEPARTMENT EMPLOYEE # id * name o location composed of assigned to # id * name o age 17

ER Modelling conventions Entity Soft box Singular name Unique Uppercase Attribute Singular name Unique within the entity Lowercase Mandatory (*) Optional(o) Unique identifier (#) 18

ER Modelling conventions Relationship Line connecting to entities Name: descriptive phrase (assigned to, composed of) Mandatory: solid line Optional: dashed line One: single line Many: crow s foot 19

ER Notation Are read clockwise Each source entity {may be must be} relationship name {one and only one one or more} destination entity 20

ER Notation DEPARTMENT EMPLOYEE # id * name o location composed of assigned to # id * name o age Each DEPARTMENT may be composed of one or more EMPLOYEES Each EMPLOYEE must be assigned to one and only one DEPARTMENT 21

Relationships examples One-to-one (1:1) DEPARTMENT led by head of EMPLOYEE Every department is led by exactly one employee An employee can be head of at most one department 22

Relationships examples One-to-many (1:N) INSTRUCTOR teacher of taught by COURSE Each instructor may be teacher of one or more courses Each course must be taught by one and only one instructor 23

Relationships examples Many-to-many (M:N) STUDENT registered for taken by COURSE A student can be registered on any number of courses (including zero) A course can be taken by any number of students (including zero) 24

Modelling Relationships Many-to-many Cannot be represented by the relational model Solution: create intersection or associative entities STUDENT registered for COURSE # id * last name * fist name taken by # id * name * offer date * duration 25

Modelling Relationships Many-to-many STUDENT performs COURSE ENROLMENT in COURSE # id * last name * fist name of # student id # course id * offer date contains # id * name * duration A student may perform an enrolment in a course A course may contain enrolments of students 26

Logical Design Translate the conceptual representation into the logical structure Input: conceptual model (ERD) Output: relational model, normalized relations 27

Relational Model Represents data in the form of relations Data structure data stored in the form of relational tables Data integrity Tables have to satisfy integrity constraints Data manipulation Operations are used to manipulate the stored tables to generate information 28

Data structure: table Composed by named columns and unnamed rows The rows represent occurrences of the entity EMP(empno, ename, job) Cell/ Field Tuple:row/record Attribute: column EMPNO ENAME JOB ----- ------- --------- 7369 SMITH CLERK 7499 ALLEN SALESMAN 7654 MARTIN SALESMAN 7566 JONES MANAGER 7788 SCOTT ANALYST 7844 TURNER SALESMAN 29

Relational table characteristics Every table has a unique name Columns in tables have unique names Every row is unique Order of rows is irrelevant Order of columns is irrelevant Every field value is atomic (contains a single value) 30

Primary keys (PK) Attribute or set of attributes that uniquely identify an entity instance Role: Enforce integrity Every entity in the data model must have a primary key 31

Identifying Primary keys For each entity instance, an attribute must have a non-null value the value must be unique the values must not change or become null during the table life time (time invariant) Attributes with this characteristics are candidate keys. 32

Foreign keys (FK) An attribute in a table that serves as primary key of another table Enforce referential integrity by completing an association between two entities 33

Data integrity Why? To Avoid data redundancy and inconsistency How? Using integrity constraints rules 34

Integrity constraints Domain Constraints All values of an attribute should be taken from the same domain. How to define a domain? Attribute Domain Name Description Domain Price prices Set of all possible book prices Monetary 6 digits 35

Integrity constraints Entity integrity Every table must have a primary key. Primary key must be not-null for each entity instance Insert, update and delete operations must maintain the uniqueness and existence of all primary keys. 36

Integrity constraints Referential integrity Maintains consistency between two tables with a relation. The foreign key must have a value that matches a primary key in the other table. Or be null. 37

Referential integrity EMP (empno, ename, job, projno, deptno) PROJ(projno, pname, loc) DEPT(deptno, dname, loc) An employee has to belong to a department: FK deptno can not take null value (mandatory). An employee may be assigned to a project: FK projno can take null value (optional). On both cases the FK must have a value that match a PK value in the other table. 38

Referential integrity Primary key Foreign keys EMPNO ENAME JOB PROJNO DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 102 10 7566 JONES MANAGER 100 20 PROJNO PNAME LOC DEPTNO DNAME LOC 100 SMNG BOSTON 10 ACCOUNTING NEW YORK 102 STR SEATLE 20 RESEARCH DALAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 39

From ERD to relational model ERD Relational model Entity Attribute Unique key Relationship Relational Table Attribute (column) Candidate key, primary key Foreign key 40

From ERD to relational model Example: EMPLOYEE # EMPNO * ENAME * MGR o HIREDATE assigned to composed of DEPARTMENT # DEPTNO * DNAME o LOC EMPLOYEES (DBD_TUT) MGR EMPNO ENAME HIREDATE DEPT_DEPTNO EMP_DEPT_FK DEPARTMENTS DNAME LOC DEPTNO 41

From ERD to relational model Binary 1:N relationships Introduce a foreign key in the table on the many side Binary 1:1 relationships Introduce a foreign key in the table on the optional side 42

1:N Relationships take the primary key of the table on the 1 side and insert it as a foreign key into the table on the N side INSTRUCTOR # INST_ID * INST_NAME teacher of taught by COURSE # COURSE_ID * COURSE_NAME INSTRUCTORS (DBD_TUT) INST_ID INST_NAME COU_INS_FK COURSES (DBD_TUT) COURSE_ID COURSE_NAME INS_INST_ID 43

Normalisation Objective validate and improve a logical design, satisfying constraints and avoiding duplication of data Is a process of decomposing relations with anomalies to produce smaller well-structured tables 44

Normal Forms Normalisation process First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) Boyce/Codd Normal Form (BCNF) Higher Normal Forms (4NF, ) Usually the 3NF is appropriate for realworld applications 45

Functional dependency Is a relationship between attributes Notation: A B If attribute B is functionally dependent on attribute A, then for every instance of A you can determine the value of B Ex: empno name, empno job 46

Normalisation: 1NF All table attributes values must be atomic (multi-values not allowed) By definition a relational table is in 1NF 47

Normalisation: 1NF Student(SID, SNAME, CID, CNAME, GRADE) SID SNAME CID CNAME GRADE 224 Waters M120 Database Management A M122 Software Engineering B M126 OO Programming B 421 Smith M120 Database Management B M122 Software Engineering A M125 Distributed Systems B Violation of the 1NF! 48

Normalisation: 1NF SID SNAME CID CNAME GRADE 224 Waters M120 Database Management A 224 Waters M122 Software Engineering B 224 Waters M126 OO Programming B 421 Smith M120 Database Management B 421 Smith M122 Software Engineering A 421 Smith M125 Distributed Systems B 49

Normalisation:2NF 1NF Every non-key attribute is fully functionally dependent on the primary key (no partial dependencies) No attribute is dependent on only part of the primary key, they must be dependent on the entire primary key 50

Partial dependency Normalisation:2NF SID An attribute SNAME is CID dependent CNAME on part of the primary key, but not all of the primary key 224 Example: 224 Waters Waters 224 Waters M120 Database Management M122 Software Engineering B M126 OO Programming B Student(SID, 421 Smith CID, M120 SNAME, Database Management CNAME, GRADE) B 421 Smith M122 Software Engineering A GRADE A 421 Smith M125 Distributed Systems Violation of the 2NF! B 51

Decompose to 2NF: Normalisation:2NF For each attribute in the primary key that is involved in partial dependency, create a new table All attributes that are partially dependent on that attribute should be moved to the new table Student(SID, CID, SNAME, CNAME, GRADE) Student(SID, SNAME) Class(CID, CNAME) 52

Normalisation: 3NF 2NF No transitive dependency for non-key attributes Transitive dependency: When an non-key attribute is dependent on another non-key attribute 53

Example: Normalisation: 3NF Class(CID, CNAME, CLEVEL, ROOM, CAPACITY) Violation of the 3NF! 54

Normalisation:3NF Decompose into 3NF For each non-key attribute that is transitive dependent on a non-key attribute, create a table Class(CID, CNAME, CLEVEL, ROOM, CAPACITY) Class(CID, CNAME, CLEVEL, ROOMID) Room(ROOMID, CAPACITY) 55

Data access with SQL Structured Query Language Language used to create, manipulate and maintain a relational database Official ANSI Standard language for RDBMS access 56

SQL Terminology Data Definition Language (DDL) Define the database CREATE, ALTER, or DROP a TABLE Data Manipulation Language (DML) Manipulate the data in an existing database SELECT, INSERT, UPDATE, or DELETE Data Control Language (DCL) Control user access to an existing database GRANT or REVOKE user privileges 57

Database schema Every user has a schema (account) References to an object that does not belong to the same schema must be prefixed it with the schema name Example: SELECT * FROM emp; SELECT * FROM marta.dept; Note: user marta must grant privileges on the table dept to user demo. 58

What did we cover? Requirement Analysis produces Requirements Specification Conceptual Design produces ER Model DBMS Independent Logical Design produces Relational Model DBMS Dependent Physical Design Implementation using SQL Maintenance 59

Documentation Oracle Design Dave Ensor, Ian Stevenson O'Reilly & Associates; ISBN: 1565922689; (April 1997) Oracle SQL: The essential reference David Kreines, Ken Jacobs O'Reilly & Associates; ISBN: 1565926978; (October 2000) Oracle online resources: http://otn.oracle.com 60

The end Thank you for your attention! Consultancy on database design Physics-database.support@cern.ch Questions 61