RDBMSSection 061 06 Relational DBMS DATABASE DEVELOPMENT And Franchise Colleges By MANSHA NAWAZ.

Slides:



Advertisements
Similar presentations
Relational data integrity
Advertisements

Overview Begin 6:00 Quiz15 mins6:15 Review Table Terms25 mins6:40 Short Break10 mins6:50 SQL: Creating Tables60 mins7:50 Break10 mins8:00 Lab – Creating.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
Using SQL to create tables Ways of using Databases.
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE 
Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
5 Chapter 5 Structured Query Language (SQL1) Revision.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
LOGICAL DATABASE DESIGN
Transforming Data Models into Database Designs
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Chapter 7 Constraints and Triggers Spring 2011 Instructor: Hassan Khosravi.
SQL: Constraints and Triggers Chapter 6 Ullman and Widom Certain properties we’d like our database to hold Modification of the database may break these.
Database Systems Lecture 5 Natasha Alechina
Chapters 17 & 18 Physical Database Design Methodology.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Section 3SQL Overview1 HSQ - DATABASES & SQL And Franchise Colleges 3 SQL Overview By MANSHA NAWAZ.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical.
Ad Hoc Constraints Objectives of the Lecture : To consider Ad Hoc Constraints in principle; To consider Ad Hoc Constraints in SQL; To consider other aspects.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
Natural vs. Generated Keys. Definitions Natural key—a key that occurs in the data, that uniquely identifies rows. AKA candidate key. Generated key—a key.
CSCI 3140 Module 3 – Logical Database Design for the Relational Model Theodore Chiasson Dalhousie University.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
M1G Introduction to Database Development 2. Creating a Database.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Recap of SQL Lab no 8 Advance Database Management System.
IST 220 Introduction to Databases Course Wrap-up.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 7 (Part a): Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
Data Driven Designs 99% of enterprise applications operate on database data or at least interface databases. Most common DBMS are Microsoft SQL Server,
IST 210 Constraints and Triggers. IST Constraints and Triggers Constraint: relationship among data elements DBMS should enforce the constraints.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Oracle 11g: SQL Chapter 4 Constraints.
Introduction to Database System Adisak Intana Lecturer Chapter 7 : Data Integrity.
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Visual Programing SQL Overview Section 1.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Session 1 Module 1: Introduction to Data Integrity
Database technology Introduction ER Modeling Database objects (intro) SQL.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
COP-5725 Practice Exercises
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Databases Introduction - concepts. Concepts of Relational Databases.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
CDT/1 Creating data tables and Referential Integrity Objective –To learn about the data constraints supported by SQL2 –To be able to relate tables together.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Fundamental of Database Systems
SQL: Constraints and Triggers
Integrity 5/5/2019 See scm-intranet.
Presentation transcript:

RDBMSSection Relational DBMS DATABASE DEVELOPMENT And Franchise Colleges By MANSHA NAWAZ

RDBMSSection 062 Overview In this lecture we well be looking at:  Entity Integrity.  Referential Integrity.  Discuss the effect UPDATE, DELETE and INSERT can have on Referential Integrity.

RDBMSSection 063 Entity Integrity Example: STUDENT (STUDENT#, NAME, …) –student# is the primary key –A particular student#, e.g. 'S4', can only occur once in that column of the table. –Each row in the table STUDENT represents a real-world entity. –The first row [S4, Ramesh] implies that there is a student somewhere identified by 'S4' and named 'Ramesh'. –If each row represents an real-world entity we must be able to differentiate between them. –Would you allow rows like this in a database?

RDBMSSection 064 Definition of Entity Integrity Entity Integrity requires that every attribute that participates in a primary key is not allowed to have a null (empty) value. Example: Entity Integrity continued …. This example breaks Entity Integrity –The missing ISBNX number is only part of the primary key but the identity of the row is still lost. –The table is a list of reservations by borrowers of particular books. –The row with the missing ISBNX has no meaning (or identity).

RDBMSSection 065 CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; Implementing Entity Integrity in SQL SQL provides direct support for Entity Integrity through CONSTRAINTS Always set any attribute which is part of a primary key to NOT NULL.

RDBMSSection 066 Referential Integrity Referential Integrity is to do with the use of Foreign Keys and how we can be sure that only valid values of foreign key values are stored in a database. Example: It would seem reasonable to assume that for each EMPLOYEE# in the TASK table there is an appropriate row in the EMPLOYEE table. Does the example live up to this? Not a good idea at all.

RDBMSSection 067 CREATE TABLE PUBLISHER ( PUB_CODE CHAR(4) NOT NULL, PUB_NAME CHAR(20)NOT NULL, CONSTRAINT pub_primary_key PRIMARY KEY (PUB_CODE)); CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE), CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; Implementing Referential Integrity (SQL-92) This shows a basic implementation of referential integrity. –There is more … –What happen if we delete a BOOK?

RDBMSSection 068 Why do we need to do more than just specify the foreign Key? We need to tell the RDBMS what to do in the following situations. –When a row containing an invalid foreign-key value is inserted in a table. –When a foreign key in a table is updated with an invalid value. –When a primary key that is referenced as a foreign key in another table is updated. –When a row with a primary key that is referenced as a foreign key in another table is deleted. We will deal with deletions first.

RDBMSSection 069 Referential Integrity and ON DELETE CASCADE CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON DELETE CASCADE, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; Some new syntax. –If a PUBLISHER is deleted (in the publisher table) then all matching records are deleted in the BOOK table. –It ‘cascades’ through the book table. –Is this the right strategy when a PUBLISHER is deleted?

RDBMSSection 0610 Referential Integrity and ON DELETE SET DEFAULT CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4) DEFAULT ‘CORG’, TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON DELETE SET DEFAULT, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a PUBLISHER is deleted (in the publisher table) then all matching records in the BOOK table have their PUB_CODE set to the value ‘CORG’. –This is the DEFAULT value for PUB_CODE –This is just an example of the syntax - using ‘CORG’ as the DEFAULT may not actually be a good idea.

RDBMSSection 0611 Referential Integrity and ON DELETE SET NULL CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON DELETE SET NULL, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a PUBLISHER is deleted (in the publisher table) then all matching records in the BOOK table have their PUB_CODE set to NULL. –Is this a better idea? –Perhaps we don’t want to lose the BOOK records although the PUBLISHER has been deleted.

RDBMSSection 0612 Referential Integrity and ON DELETE NO ACTION CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON DELETE NO ACTION, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a user attempts to delete a PUBLISHER (in the publisher table), and there are matching records in the BOOK table, then the delete is refused. –You have to remove all references to a particular PUB_CODE in the BOOK table before you can delete that PUBLISHER.

RDBMSSection 0613 Referential Integrity and ON UPDATE CASCADE CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON UPDATE CASCADE, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a PUB_CODE value is updated (changed) in the publisher table then all matching records are updated in the BOOK table. –It ‘cascades’ through the book table.

RDBMSSection 0614 Referential Integrity and ON UPDATE SET DEFAULT CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4) DEFAULT ‘CORG’, TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON UPDATE SET DEFAULT, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a PUB_CODE value is updated (changed) in the publisher table then all matching records in the BOOK table are set to the DEFAULT value. –Clearly not what you would do with PUBLISHER and BOOK.

RDBMSSection 0615 Referential Integrity and ON UPDATE SET NULL CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON UPDATE SET NULL, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a PUB_CODE value is updated (changed) in the publisher table then all matching records in the BOOK table are set to NULL. –Again probably a bad idea for this example but useful in other situations.

RDBMSSection 0616 Referential Integrity and ON UPDATE NO ACTION CREATE TABLE BOOK ( ISBN CHAR(8) NOT NULL, PUB_CODE CHAR(4), TITLE CHAR(40), PUB_DATE CHAR(4), NOW_PRICE NUMBER(10,2), CONSTRAINT book_foreign_key FOREIGN KEY (PUB_CODE) REFERENCES PUBLISHER (PUB_CODE) ON UPDATE NO ACTION, CONSTRAINT book_primary_key PRIMARY KEY (ISBN) ) ; If a user attempts to change a PUB_CODE value in the publisher table, and there are matching records in the BOOK table, then the delete is refused.

RDBMSSection 0617 Referential Integrity continued... Finally: –Most normal updates will not cause such problems. –Inserting a new BOOK row with a valid PUB_CODE will have no effect on Referential Integrity. –Deleting PUBLISHERS or updating PUB_CODEs in the PUBLISHER table are quite rare events.

RDBMSSection 0618 Referential Integrity – MS SQL Server 2000 Enterprise Manager

RDBMSSection 0619 END OF LECTURE