Data Integrity An empty database is a correct database.

Slides:



Advertisements
Similar presentations
MSc IT UFCE8K-15-M Data Management Prakash Chatterjee Room 2Q18
Advertisements

The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Relational Database Design UNIT II 1. 2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Relations The Relational Data Model John Sieg, UMass Lowell.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Fundamentals of Relational Database Yong Choi School of Business CSUB, Bakersfield.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE 
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Transforming Data Models into Database Designs
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
Database Architecture The Relational Database Model.
Chapter 14 & 15 Conceptual & Logical Database Design Methodology
Chapter 6: Integrity Objective Key Constraints (Chapter 2) Cardinality Constraints (Chapter 2) Domain Constraints Referential Integrity Assertions Triggers.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
Module Title? DBMS E-R Model to Relational Model.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
Fundamentals of Relational Database Yong Choi School of Business CSUB, Bakersfield.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Copyright © Curt Hill The Relational Model of Database Basic organization and terms.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
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.
INTRODUCTION lecture1 1. Data base concept Data is a meaningless static value. What does 3421 means? Information is the data you process in a manner that.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Chapter 4 The Relational Model Pearson Education © 2009.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Getting started with Accurately Storing Data
Chapter 6: Integrity (and Security)
COP Introduction to Database Structures
Chapter 6 - Database Implementation and Use
Lecture 2 The Relational Model
Lecture # 13 (After 1st Exam)
SQL: Constraints and Triggers
Introduction lecture1.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Transparencies
Database solutions Chosen aspects of the relational model Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Database Design: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
INSTRUCTOR: MRS T.G. ZHOU
Presentation transcript:

Data Integrity An empty database is a correct database

Overview Review Domains What are integrity constraints? Gulf between the theory and the implementation Testing insertions into database? NULLS

Review Tuple Cardinality Attribute Degree Domain

Domains Conceptual pool of values from which one or more columns draw their values Named set of scalar values all the same type –scalar is smallest semantic unit of data, individual data value CREATE DOMAIN …? ? Domain contains ALL permitted values, static Which relations in the database contain any information pertaining to suppliers?

Comparisons with Domains Domains constrain comparisons, =,<> domain-check override Codd Logically equivalent statements must have same semantic interpretation Logic cannot be nullified a = cT b = c T a = bF Arithmetic operators

Data Types Hide complexity within domain DATE domain –three integers (d,m,y) –interpreted by operators Address domain –USA - street, city, state, zip

ADT in Oracle Simulate a domain CREATE TYPE ADDR_TY AS OBJECT –(STREETVARCHAR2(50), –CITYVARCHAR2(25), –STATECHAR(2), –ZIPVARCHAR(9)); CREATE TABLE NEW_CUSTOMER –( CUSTID VARCHAR2(9) PRIMARY KEY, –CUST_NAME VARCHAR2(25), –ADDRESS ADDR_TY);

Relations Abstract object A relation, r, on a collection of domains, D1, D2 …Dn consists of two parts a heading and a body –heading - fixed set of attributes, pairs –body - set of tuples, pairs Named relation is really a variable Relations dynamic Table is concrete picture

Candidate Keys Subset of all attributes that are –Unique –Irreducibile Does not relate to current data set but to set of ALL POSSIBLE values –simple –composite Provide tuple-level addrressing mechanism Primary key is selected from candidate key. Others called Alternate keys

Is our information Correct ? Consistent ? Logical ?

Start with a consistent database Update the database Result a consistent database

Is the data consistent? t Is the data consistent between tables? t Are the same values equivalent? t Do foreign keys reference existent primary keys? t Has logical consistency been maintained? t Have the business rules been enforced? t All constraints valid?

How do we maintain correct, consistent data ? t Data Integrity Rules –Candidate keys –Domains t Referential Integrity Rules –Foreign keys t Business Rules –Constraints –Stored Procedures, Triggers

Where do we maintain correct, consistent data ? Database creation –base tables –views Implementation –back end –front end applications –middleware Integrity rules are database specific

Foreign Keys If the foreign key contains either matching values or nulls, the table(s) that make use of such a foreign key are said to exhibit referential integrity. An attribute in one table refers to a primary key in another table –can it be a candidate key? –can it be the same table? A FK is composite if the primary key is composite.Referential Integrity assures that no invalid foreign keys permitted Relationships formed through foreign keys but not exclusively

Maintaining Integrity with Foreign Keys Correct DB Transform thru update Delete Parent restrict cascades Update Parent restrict cascade How many levels of cascade? Define procedures Note: Correct database satisfies logical AND of all known rules

Entity Integrity No component of the primary key of a base relation is allowed to accept NULLS. In a relational database, we never record information about something we cannot identify. No attribute included in composite primary key can be NULL. Can alternate keys have NULLS?

Null Foreign Keys Can a foreign key be null? –definition - matches primary key or is null Can a composite foreign key have some attributes null? ON DELETE SET NULL –allows child record to remain but deleted key attribute becomes null

Rules or Constraints Theory –CREATE INTERGIRTY RULE PR4 FORALL PX(PX.WEIGHT>0) ON ATTMPTED VIOLATION REJECT; Oracle –CREATE TABLE PX... WEIGHT NUMBER CONSTRAINT PR4 CHECK (WEIGHT >0); Components name, truth-statement, violation response

Relation Rules or Constraints Theory –CREATE INTERGIRTY RULE SR8 FORALL S(IF S.CITY = ‘LONDON’ THEN S.STATUS = 20) ON ATTMPTED VIOLATION REJECT; Oracle Must be closed WFF

Database Rules CREATE INTEGRITY RULE C95 –FORALL SX (FORALL SPX –(IF SX.STATUS < 20 AND –SX.S# = SPX.S# –THEN SPX>QTY <=500)); Oracle Note required join condition

Database Rules How do we execute the following: –For every orderline there must exist an order. –Every customer must place an order. –No salesrep can have more than 200 customers. –Every orderline must contain a valid part. When do we execute

Transition Rules Applied as go from one state to another Employee marries CREATE INTEGRITY RULE S12 –IF S’.S# = S.S# THEN –S’.STATUS < S.STATUS;