Transforming ER to Relational Schema

Similar documents
DB Creation with SQL DDL

Standard Query Language. SQL: Data Definition Transparencies

Lecture 07. Spring 2018 Borough of Manhattan Community College

Lecture 5 Data Definition Language (DDL)

Lecture 6 Structured Query Language (SQL)

Example 1 - Create Horizontal View. Example 2 - Create Vertical View. Views. Views

3ISY402 DATABASE SYSTEMS

STRUCTURED QUERY LANGUAGE (SQL)

Chapter 3. The Relational database design

Lecture 03. Fall 2017 Borough of Manhattan Community College

Lecture 03. Spring 2018 Borough of Manhattan Community College

Conceptual Database Design

DBMS Chapter Three IS304. Database Normalization-Comp.

Database Technologies. Madalina CROITORU IUT Montpellier

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

Chapter 6. SQL Data Manipulation

Physical Database Design

CMP-3440 Database Systems


CMP-3440 Database Systems

Relational Database Systems Part 01. Karine Reis Ferreira

LECTURE 6: GUIDELINES FOR GOOD RELATIONAL DESIGN MAPPING ERD TO RELATIONS

OBJECTIVES. How to derive a set of relations from a conceptual data model. How to validate these relations using the technique of normalization.

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Lecture 10. Spring 2018 Borough of Manhattan Community College

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

Multiple-Choice. 1. Which of the following is equivalent to a table? (3 pts.) a. record b. relation c. relationship d. constraint e.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

Review -Chapter 4. Review -Chapter 5

SQL Interview Questions

Chapter 17. Methodology Logical Database Design for the Relational Model

CS317 File and Database Systems

Relational Data Model ( 관계형데이터모델 )

MTA Database Administrator Fundamentals Course

Normalisation. Normalisation. Normalisation

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

Lab # 4. Data Definition Language (DDL)

CPS510 Database System Design Primitive SYSTEM STRUCTURE

Data Storage and Query Answering. Data Storage and Disk Structure (4)

DATABASES SQL INFOTEK SOLUTIONS TEAM

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

Solved MCQ on fundamental of DBMS. Set-1

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

The Relational Model

Chapter 4. The Relational Model

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Entity Relationship Modeling

DATABASE MANAGEMENT SYSTEMS. UNIT I Introduction to Database Systems

Assignment Session : July-March

The Structured Query Language Get Started

Elements of the E-R Model

CS317 File and Database Systems

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

CS317 File and Database Systems

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

1. (a) Briefly explain the Database Design process. (b) Define these terms: Entity, Entity set, Attribute, Key. [7+8] FIRSTRANKER

D.K.M COLLEGE FOR WOMEN(AUTONOMOUS),VELLORE DATABASE MANAGEMENT SYSTEM QUESTION BANK

Lecture4: Guidelines for good relational design Mapping ERD to Relation. Ref. Chapter3

namib I A U n IVERS I TY

DATABASE MANAGEMENT SYSTEM

Lecture 01. Fall 2018 Borough of Manhattan Community College

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g.

RELATIONAL DATA MODEL

CS317 File and Database Systems

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Data analysis and design Unit number: 23 Level: 5 Credit value: 15 Guided learning hours: 60 Unit reference number: H/601/1991.

Database Normalization

COSC Assignment 2

Chapter 1 SQL and Data

DATABASE MANAGEMENT SYSTEMS

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

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

CS2255 DATABASE MANAGEMENT SYSTEMS QUESTION BANK UNIT I

CSCC43H: Introduction to Databases. Lecture 4

INTRODUCTION TO DATABASE

EXAMINATION FOR THE BSC (HONS) IN INFORMATION SYSTEMS; YEAR 2

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

COMP102: Introduction to Databases, 5 & 6

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

Database Systems. A Practical Approach to Design, Implementation, and Management. Database Systems. Thomas Connolly Carolyn Begg

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

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

CS317 File and Database Systems

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

Lecture 09. Spring 2018 Borough of Manhattan Community College

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

Copyright 2004 Pearson Education, Inc.

Database design process

Today Learning outcomes LO2

ADVANCED QUERY AND VIEWS

Normalization. { Ronak Panchal }

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

Course Outline Faculty of Computing and Information Technology

Logical Database Design. ICT285 Databases: Topic 06

Transcription:

Transforming ER to Relational Schema Transformation of ER Diagrams to Relational Schema ER Diagrams Entities (Strong, Weak) Relationships Attributes (Multivalued, Derived,..) Generalization Relational Schema Relations Attributes (Atomic) 1. Removing multivalued/composite attributes 2. Removing generalization 3. Removing weak entities 4. Transforming entities 5. Transforming relationships

Relations for the Staff View of DreamHome Remove Multi-Valued/Composite Attributes

Remove Generalization Hierarchies Owner ownerno {PK} address telno type fname lname bname btype contactname PrivateOwner ownerno {PK} address telno fname lname BusinessOwner ownerno {PK} address telno bname btype contactname Transforming Entities Create a relation that includes all simple attributes of that entity. For composite attributes, include only constituent simple attributes. Staff (staffno, fname, lname, position, sex, DOB) Primary Key (staffno)

Many-to-Many Binary Relationship Many-to-One Binary Relationship

Relations for the Staff View of DreamHome Normalization Make a relation schema normal: A single relation stores a single type of information. Data redundancy leads Insertion Anomaly Deletion Anomaly Update Anomaly as well as storage waste

Functional Dependency Normalization (1NF to BCNF) 2NF PropertyInspection (propertyno, idate, itime, comments, staffno, sname, carreg) Property (propertyno, paddress) 3NF Staff (staffno, sname) PropertyInspect (propertyno, idate, itime, comments, staffno, carreg) BCNF: For A B, A is a superkey or A B BCNF StaffCar (idate, staffno, carreg) Inspection (propertyno, idate, itime, comment, staffno)

Relationship Between Normal Forms UNF 1NF: Atomic attribute values 2NF: 1NF & No partial dependency 3NF: 2NF & No transitive dependency BCNF: 1NF and only superkey dependency Objectives of SQL Ideally, database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from relations; perform simple and complex queries. SQL consists of two major components: A DDL for defining database structure. A DML for retrieving and updating data. Until SQL3, SQL did not contain flow of control commands. Cf. Flow of control: sequence, branch, loop, (function call)

Standard English Words in SQL 1) CREATE TABLE Staff(staffNo VARCHAR(5), lname VARCHAR(15), salary DECIMAL(7,2)); 2) INSERT INTO Staff VALUES ( SG16, Brown, 8300); 3) SELECT staffno, lname, salary FROM Staff WHERE salary > 10000; Used by application developers, DBAs, management, and even end users. ISO SQL standards vs. Vendor-specific features ISO SQL Data Types

More on Data Types Exact Numeric: NUMERIC, DECIMAL, INTEGER, SMALLINT Fixed point numbers: Precision and Scale [ ][ ][ ].[ ][ ] : NUMERIC (5,2) Approximate Numeric Floating point numbers: Fraction and Exponent Characters and Bits 2 8 = 256 : A byte can represent 256 distinct symbols (signals) ASCII needs only 128 symbols => MSB for control How to handle Asian alphabets such as Korean Two byte code: [Byte-1][Byte-2] Common Error in Floating Point Number Comparison #include <stdio.h> main() { float a, b, c; a = 1.345f; b = 1.123f; c = a + b; if (c == 2.468) printf( Equal.\n"); else printf( Not equal! The value of c is %13.10f,or %f",c,c); } Execution Not equal! The value of c is 2.4679999352 or 2.468000.

IEEE 754 for Floating Point Numbers Single-Precision Sign: 1 bit, Exponent: 8 bits (with bias), Fraction: 23 bits Example: -118.625 Negative Sign bit = 1 118.625 (10) = 1110110.101 (2) 1110110.101 = 1.110110101 x 2 6 Fraction = 110110101 with following zero s up to 23 bits Exponent: 6 127(2 8 /2 1) + 6 = 133 = 10000101 (2) 1 8 23 +-+--------+-----------------------+ S Exp Fraction 1 10000101 11011010100000000000000 +-+--------+-----------------------+ 31 30 23 22 0 Data Definition Main SQL DDL statements are: CREATE SCHEMA CREATE/ALTER TABLE CREATE VIEW DROP SCHEMA DROP TABLE DROP VIEW Many DBMSs also provide: CREATE INDEX DROP INDEX

CREATE SCHEMA / TABLE CREATE SCHEMA Name DROP SCHEMA Name CREATE TABLE PropertyForRent ( propertyno varchar(5) NOT NULL, rooms smallint NOT NULL, DEFAULT 4, rent decimal(6,2) NOT NULL, DEFAULT 600, ownerno varchar(5) NOT NULL, staffno varchar(5), branchno varchar(5) NOT NULL, PRIMARY KEY (propertyno), FOREIGN KEY (staffno) REFERENCES Staff ) Integrity Constraints Entity Integrity Primary key of a table must contain a unique, non-null value for each record. PRIMARY KEY (propertyno) Can only have one PRIMARY KEY clause per table. Can still ensure uniqueness for alternate keys using UNIQUE: UNIQUE(telNo) Referential Integrity if FK contains a value, it must refer to an existing row in its parent table. FOREIGN KEY(branchNo) REFERENCES Branch FOREIGN KEY (staffno) REFERENCES Staff ON DELETE SET NULL FOREIGN KEY (ownerno) REFERENCES Owner ON UPDATE CASCADE Enterprise Constraints CREATE ASSERTION StaffNotHandlingTooMuch CHECK (NOT EXISTS (SELECT staffno FROM PropertyForRent GROUP BY staffno HAVING COUNT(*) > 100))

ALTER/DROP TABLE ALTER TABLE Client ADD prefnorooms PRooms; DROP TABLE TableName [RESTRICT CASCADE] DROP TABLE PropertyForRent; Removes named table and all rows within it. With RESTRICT, if any other objects depend for their existence on continued existence of this table, SQL does not allow it. With CASCADE, SQL drops all dependent objects (and objects dependent on these objects). CREATE VIEW Create view so that manager at branch B003 can only see details for staff who work in his or her office. CREATE VIEW Manager3Staff AS SELECT * FROM Staff WHERE branchno = B003 ; Create view of staff details at branch B003 excluding salaries. CREATE VIEW Staff3 AS SELECT staffno, fname, lname, position, sex FROM Staff WHERE branchno = B003 ;

CREATE INDEX CREATE INDEX myindex on Staff(Name); Staff Transactions Concurrency Control Normal Banking Your Account = 50,000: Balance (DB) = 50,000 Read it at Branch A: Balance (Teller A) = 50,000 Draw 30,000: Balance (Teller A) = 20,000 Write it back: Balance (DB) = 20,000 Abnormal Banking Your Account = 50,000 Read it at Branch A: Balance (DB) = 50,000 Draw 30,000: Balance (Teller A) = 20,000 Read it at Branch B: Balance (Teller B) = 50,000 (Oops!!) Draw 40,000: Balance (Teller B) = 10,000 Write it back at A: Balance (DB) = 20,000 Write it back at B: Balance (DB) = 10,000 In Your Pocket = 70,000 while Balance is still 10,000

Transactions Transactions Atomicity Consistency Isolation Durability SQL defines transaction model based on COMMIT and ROLLBACK. Transaction is logical unit of work with one or more SQL statements guaranteed to be atomic with respect to recovery. An SQL transaction automatically begins with a transaction-initiating SQL statement (e.g., SELECT, INSERT). Changes made by transaction are not visible to other concurrently executing transactions until transaction completes. Access Control Give Manager full privileges to Staff table. GRANT ALL PRIVILEGES ON Staff TO Manager WITH GRANT OPTION; Give users Personnel and Director SELECT and UPDATE on column salary of Staff. GRANT SELECT, UPDATE (salary) ON Staff TO Personnel, Director; Give all users SELECT on Branch table. GRANT SELECT ON Branch TO PUBLIC; Revoke privilege SELECT on Branch table from all users. REVOKE SELECT ON Branch FROM PUBLIC; Revoke all privileges given to Director on Staff table. REVOKE ALL PRIVILEGES ON Staff FROM Director;

Summary Transforming ER Diagrams into Relational Schema Normalization SQL Concepts Data Types Schema/Table/View Creation Transactions and Access Control