Integrity 5/5/2019 See scm-intranet.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Candidate Keys Objectives of the Lecture : To consider Integrity Constraints; To consider the principles of Candidate Keys; To consider Candidate Keys.
Introduction to Structured Query Language (SQL)
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 Pertemuan 11 SQL Data Definition Matakuliah: >/ > Tahun: > Versi: >
Introduction to Structured Query Language (SQL)
Data Integrity Constraints
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Database Technical Session By: Prof. Adarsh Patel.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
RDBMSSection Relational DBMS DATABASE DEVELOPMENT And Franchise Colleges By MANSHA NAWAZ.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
M1G Introduction to Database Development 2. Creating a Database.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 Chapter 17 Methodology - Local Logical Database Design.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
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.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
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,
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
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.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
Getting started with Accurately Storing Data
CompSci 280 S Introduction to Software Development
Fundamentals of DBMS Notes-1.
Chapter 6: Integrity (and Security)
COP Introduction to Database Structures
國立臺北科技大學 課程:資料庫系統 Chapter 7 SQL Data Definition.
SQL: Schema Definition and Constraints Chapter 6 week 6
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Constraints and Triggers
Chapter 7 SQL – Data Definition Pearson Education © 2014.
Minggu 5, Pertemuan 9 SQL: Data Definition
Lecture # 13 (After 1st Exam)
SQL: Constraints and Triggers
Module 5: Implementing Data Integrity by Using Constraints
CPSC-310 Database Systems
The Relational Model Relational Data Model
SQL DATA CONSTRAINTS.
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Relational Database Design
Database Design: Relational Model
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Domains 4/17/2019 See scm-intranet.
SQL-Data Definition 4/21/2019.
INSTRUCTOR: MRS T.G. ZHOU
SQL – Constraints & Triggers
CPSC-608 Database Systems
Triggers 7/11/2019 See scm-intranet.
CS 405G: Introduction to Database Systems
Presentation transcript:

Integrity 5/5/2019 See scm-intranet

Objectives   To develop an understanding of integrity and integrity constraints. To develop a means of expressing constraints 5/5/2019 See scm-intranet

Integrity Constraints Constraints allow only valid combinations of data in database. Need to ensure data manipulation operations are correct. Constraints can be enforced by the DBMS, application program, or user. Universally applied to all users only when defined in DBMS logical schema. 5/5/2019 See scm-intranet

Therefore designer must be able to DBMS should prevent invalid operations. or carry out compensatory actions to mitigate effects of operation. Therefore designer must be able to identify and reject offending operations or identify and implement a compensatory operation to ensure database left in a valid state. 5/5/2019 See scm-intranet

Referential Integrity No primary key attribute(s) should have a null value or hold duplicate values. If a base relation includes a foreign key then every value of the foreign key must be equal to a value of a primary key in a relation. or be wholly null.   5/5/2019 See scm-intranet

SQL-92 e.g.may have this clause for table ‘employee’ for instance- FOREIGN KEY(branch_no) REFERENCES branch ; clause in CREATE and ALTER statements. INSERT/UPDATE rejected if attempt made to create a foreign key value in base relation holding foreign key without a matching candidate in base relation with primary key. E.g. cannot insert a branch_no until that value exists in primary key of table branch 5/5/2019 See scm-intranet

Referential Action FOREIGN KEY clause has ON UPDATE and ON DELETE subclauses- referential action. E.g. FOREIGN KEY (staff_no) REFERENCES staff ON DELETE SET NULL; 5/5/2019 See scm-intranet

Referential Action Possibilities CASCADE- delete from primary key table and matching rows in foreign key table. Deleted rows may have a candidate key used as a foreign key in another table so FOREIGN KEY rules for this may be triggered. RESTRICT-can only delete from primary key table after all matching foreign key references deleted SET NULL/DEFAULT- delete row from primary key table and set foreign key values to NULL or default value. NO ACTION- rejects delete operation. Similar for Update operations 5/5/2019 See scm-intranet

Example Create table Car (reg_no char(8), model varchar(20), engine_size integer, constraint car_key primary key (reg_no) constraint is_costed_at foreign key (engine_size) references hire-rate, constraint is_of_type foreign key (model) references type_of_car… Assumes tables hire_rate and type_of_car exist 5/5/2019 See scm-intranet

What happens to Car if an engine_size is removed/updated in Hire_rate? Is_costed_at Car Type_of_car Hire_Rate Is_of_type 0..* 1..1 Car (registration_no, model, engine_size) Type_of_car (model, make) Hire_rate (engine_size, daily_hire_rate) When considering referential action the questions to ask here would be- What happens to Car if an engine_size is removed/updated in Hire_rate? What happens to Car if a Model is removed/updated in Type_of_Car? What happens to foreign key values in a primary/foreign key relationship if the target (primary key) of a foreign key reference is removed/updated? 5/5/2019 See scm-intranet

uses RESTRICT referential action unless programmed otherwise. SQL Server 7 uses RESTRICT referential action unless programmed otherwise. This means that data/tables can only be deleted/dropped in order i.e. data/tables at many ends (foreign key end ) of relationships first. SQL Server 2000 CASCADE and NO ACTION available explicitly. RESTRICT used if no referential action specified explicitly Cascade does not apply to DROP so order of dropping tables still applies 5/5/2019 See scm-intranet

Dialogue above exists for client-side databases With Server-side referential integrity defined via the SQL schema 5/5/2019 See scm-intranet

Equivalent dialogue server-side 5/5/2019 See scm-intranet

Summary Data Integrity is a necessary feature of any database system. Referential integrity rules are necessary in relational database systems. SQL provides a means of specifying foreign keys and the associated referential actions 5/5/2019 See scm-intranet