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



Similar documents
Normalization of Database

Oracle Database: SQL and PL/SQL Fundamentals

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

SQL, PL/SQL FALL Semester 2013

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle SQL. Course Summary. Duration. Objectives

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

1. INTRODUCTION TO RDBMS

Oracle Database 10g: Introduction to SQL

IT2304: Database Systems 1 (DBS 1)

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

Oracle Database: SQL and PL/SQL Fundamentals

1 Structured Query Language: Again. 2 Joining Tables

IT2305 Database Systems I (Compulsory)

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

Instant SQL Programming

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries


T-SQL STANDARD ELEMENTS

Databases in Engineering / Lab-1 (MS-Access/SQL)

Fundamentals of Database Design

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

Oracle Database 12c: Introduction to SQL Ed 1.1

Database Programming with PL/SQL: Learning Objectives

Programming with SQL

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

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

Oracle 10g PL/SQL Training

Foundations of Information Management

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

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

Tutorial on Relational Database Design

Databases What the Specification Says

Database Migration from MySQL to RDM Server

DATABASE MANAGEMENT SYSTEMS


P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur

A basic create statement for a simple student table would look like the following.

How To Create A Table In Sql (Ahem)

Oracle Database 11g SQL

SQL Server 2008 Core Skills. Gary Young 2011

2. Oracle SQL*PLUS Winter Some SQL Commands. To connect to a CS server, do:

Oracle Database: SQL and PL/SQL Fundamentals NEW

TIM 50 - Business Information Systems

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Introduction to Microsoft Jet SQL

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

5. CHANGING STRUCTURE AND DATA


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

Chapter 5. SQL: Queries, Constraints, Triggers

- Suresh Khanal. Microsoft Excel Short Questions and Answers 1

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Benefits of Normalisation in a Data Base - Part 1

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

Relational Database: Additional Operations on Relations; SQL

BCA. Database Management System

Database Management System

7. Databases and Database Management Systems

Database Management Systems 2015

Using Databases With LabVIEW

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Foundations of Information Management

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Database Query 1: SQL Basics

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Fundamentals of Database System

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Advance DBMS. Structured Query Language (SQL)

Course Title: Microsoft Access Basic Duration: 12 hours

Information Systems SQL. Nikolaj Popov

Database Administration with MySQL

Database Design and Normalization

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

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Oracle Database 10g Express

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

A Brief Introduction to MySQL

Structured Query Language (SQL)

SQL. by Steven Holzner, Ph.D. ALPHA. A member of Penguin Group (USA) Inc.

DBMS / Business Intelligence, SQL Server

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

DATABASE DESIGN & PROGRAMMING WITH SQL COURSE CODE: 5324

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

Access Database Design

5.5 Copyright 2011 Pearson Education, Inc. publishing as Prentice Hall. Figure 5-2

SQL. Short introduction

Creating Database Tables in Microsoft SQL Server

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

Basic Concepts of Database Systems

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

Netezza SQL Class Outline

DATABASE NORMALIZATION

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

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

Oracle Database Links Part 2 - Distributed Transactions Written and presented by Joel Goodman October 15th 2009

Transcription:

Normalization of databases Database normalization is a technique of organizing the data in the database. Normalization is a systematic approach of decomposing tables to eliminate data redundancy and undesirable characteristics such as insertion, update and delete anomalies. It is a multi-step process that puts data in to tabular form by removing duplicated data from the relational table. Normalization is used mainly for 2 purpose. - Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically Problems without normalization Without normalization, it becomes difficult to handle and update the database, without facing data loss. Insertion, update and delete anomalies are very frequent is databases are not normalized. Example :- S_Id S_Name S_Address Subjects_opted 401 Adam Colombo-4 Bio 402 Alex Kandy Maths 403 Steuart Ja-Ela Maths 404 Adam Colombo-4 Chemistry Updation Anomaly To update the address of a student who occurs twice or more than twice in a table, we will have to update S_Address column in all the rows, else data will be inconsistent. Insertion Anomaly Suppose we have a student (S_Id), name and address of a student but if student has not opted for any subjects yet then we have to insert null, which leads to an insertion anomaly. Deletion Anomaly If (S_id) 401 has opted for one subject only and temporarily he drops it, when we delete that row, entire student record will get deleted. Normalisation Rules 1 st Normal Form No two rows of data must contain repeating group of information. Ie. Each set of column must have a unique value, such that multiple columns cannot be used to fetch the same row. Each row should have a primary key that distinguishes it uniquely. Primary Key The primary key is usually a single column, but sometimes more than one column can be combined to create a single primary key. Example Student Table (Before 1 st Normal form) Student Age Subject Adam 20 Bio, Maths Alex 21 Maths Steuart 19 Maths

In 1 st normal form, any row must not have a column in which more than one value is saved. However in 1 st normal form, data redundancy will increase as there will be many columns with the same data in multiple rows, but each row as a whole will be unique. Student Table (After 1 st Normal form) Student Age Subject Adam 20 Bio Adam 20 Maths Alex 21 Maths Steuart 19 Maths 2 nd normal form In the 2 nd normal form there should not be any partial dependency of any columns on primary key. A table that has concatenated primary key, each column in the table that is not part of the primary key must depend upon the entire concatenated key for its existence. Student Table (Before 2 nd Normal form) Student Age Subject Adam 20 Bio Adam 20 Maths Alex 21 Maths Steuart 19 Maths Student Table (After 2 nd Normal form) Student Age Adam 20 Alex 21 Steuart 19 Student Adam Adam Alex Steuart Subject Bio Maths Maths Maths While the candidate key is (Student, Subject), Age of student only depends on Student column. 3 rd normal form Every non-prime attribute of table must be dependent on primary key. The transitive functional dependency must be removed from the table.

Example Student_Detail table (before 3 rd normal form) Student_Id Student_Name DOB Street City State Zip In this table Student_Id is the primary key, but street, city and State depends on Zip. The dependency between Zip and other fields is called transitive dependency. Hence, to apply 3 rd normal form, we need to remove Street, City and State to a new table with Zip as a primary key. Student_Detail table (after 3 rd normal form) Student_Id Student_Name DOB Address table Zip Street City State The advantage of removing transitive dependency is as follows. - Amount of data duplication is removed - Data integrity achieved Entity Relationship Diagram An entity diagram is a visual representation of how data is related to each other. Entity An entity is a person, place or object which is represented as rectangles. Attribute Attributes are properties of an entity. Each attribute will have a type Eg:-Student_Name : VARCHAR (50) Student_DOB : DATETIME Teacher_Qualification : VARCHAR (100) Student_Age :NUMERIC Relationship There are 4 types of relationships that could exist between entities. Many to many relationships should be resolved using an intermediate entity. - One-to-one (Eg:-Husband and Wife) - One-to-many (Eg:-Student and Student_Detail) - Many-to-one - Many-to-many (Eg:-Student and Address) Student 1 1..* Student_ Detail

Structured Query Language (SQL) SQL is a programming language used for storing and managing data in RDBMS. All RDBMS (SQL Server, Oracle, MySQL, MS Access) use SQL as the standard database language. SQL is used to perform all types of operations in a database. The following SQL commands are usually used. Data Definition Language (DDL) All DDL commands are auto committed. CREATE ALTER TRUNCATE DROP RENAME To create new table or database For alteration Delete data from table Drop a table To rename a table Data Manipulation Language (DML) DML commands are not auto committed. They can be rolled back. INSERT UPDATE DELETE MERGE To create new table or database For alteration Delete data from table Drop a table Data Query Language (DQL) SELECT Retrieve records from one or more tables Data Control Language (DCL) GRANT REVOKE Grant permission of right Take back permission Transactional Control Language (TCL) COMMIT ROLLBACK SAVEPOINT To permanently save To undo change To save temporarily

CREATE statement CREATE DATABASE Tuition; CREATE TABLE Student (Student_IdVARCHAR(10), Student_Name VARCHAR(50), DOB DATETIME ); ALTER statement ALTER TABLE Student add (Address VARCHAR(100)); ALTER TABLE Student add (Address VARCHAR(100), default 'Colombo-5'); ALTER TABLE Student rename Address to Location; ALTER TABLE Student drop Location; DROP statement DROP TABLE Student DROP DATABASE Tuition RENAME statement Rename TABLE Student to Student_Record INSERT statement INSERT into Student values ('100', 'Silva', '1-JAN-1990') UPDATE statement UPDATE Student set Student_Name='Kumar' where Student_Id='100' DELETE statement DELETE from Student where Student_Id='100' GRANT and REVOKE statement GRANT create table to UserName REVOKE create table from UserName SQL queries SELECT * FROM Student WHERE Student_NameLIKE 'a%' ORDER BY asc GROUP BY Student_AGE HAVING Student_AGE>20

SQL Functions 1. AVG SELECT AVG(Student_Marks) FROM Marks 2. COUNT SELECT COUNT(Student_Name) FROM Student 3. DISTINCT SELECT COUNT(DISTINCT Salary) FROM Employee 4. FIRST SELECT FIRST(Student_Name) FROM Student ORDERBY Age 5. LAST SELECT LAST(Student_Name) FROM Student ORDERBY Age 6. MAX SELECT MAX(Student_Marks) FROM Marks 7. MIN SELECT MIN(Student_Marks) FROM Marks 8. SUM SELECT SUM(Salary) FROM Employee 9. ROUND SELECT ROUND(Salary) FROM Employee 10. MID SELECT MID(Employee_Name, 1, 10) FROM Employee 11. LCASE SELECT LCASE(Employee_Name) 12. UCASE SELECT UCASE(Employee_Name) AND and OR Operators AND SELECT * FROM Employee WHERE Employee_Salary>25,000 AND Employee_Age<25 OR SELECT * FROM Employee WHERE Employee_Salary>25,000 OR Employee_Sage<25

Database Keys 1. Primary Key Primary Key helps to uniquely identify a row. Primary key could either be a single attribute or a group of attributes (composite keys) Eg1-Student_ID for Student table. Eg2-Student_ID and Subject_ID for Marks table 2. Foreign Key A key which is primary key when referred in another table is made as a foreign key. Foreign Key is used to relate 2 tables. Eg:-Emp_Id is a foreign key for Emp_Salary table UNION and INTERSECT UNION SELECT * FROM A UNION ALL SELECT * FROM B will obtain all records from both tables, excluding common records. UNION ALL SELECT * FROM A UNION ALL SELECT * FROM B will obtain all records from both tables, including common records. INTERSECT SELECT * FROM A UNION ALL SELECT * FROM B will obtain all records from both tables, which are common records. MINUS SELECT * FROM A MINUS SELECT * FROM B will remove all common records in both tables as well unique records in table B Alias Alias will rename the query results as something different from the table name. SELECT Emp_Name FROM Employee AS NAME