Geo-Databases: lecture 6 Data Integrity

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

MSc IT UFCE8K-15-M Data Management Prakash Chatterjee Room 2Q18
1 Constraints, Triggers and Active Databases Chapter 9.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
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.
Fall 2001Arthur Keller – CS 1809–1 Schedule Today Oct. 23 (T) Constraints. u Read Sections Assignment 4 due. Project Part 3 due Oct. 24 (W). Oct.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
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.
Chapter 6: Integrity Objective Key Constraints (Chapter 2) Cardinality Constraints (Chapter 2) Domain Constraints Referential Integrity Assertions Triggers.
SQL Constraints & Triggers May 10 th, Agenda Big picture –what are constraints & triggers? –where do they appear? –why are they important? In SQL.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Department of Geoinformation Science Technische Universität Berlin WS 2006/07 Geoinformation Technology: lecture 3 Mapping of OO Models onto Tables Prof.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
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.
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.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Lecture 03 Constraints. Example Schema CONSTRAINTS.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Embedded SQL, JDBC. u Read Sections.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
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.
Fundamentals of DBMS Notes-1.
Chapter 6: Integrity (and Security)
SQL: Schema Definition and Constraints Chapter 6 week 6
CS 480: Database Systems Lecture 13 February 13,2013.
Constraints and Triggers
Foreign Keys Local and Global Constraints Triggers
Lecture 2 The Relational Model
CPSC-608 Database Systems
Database Systems Instructor Name: Lecture-12.
Geo-Databases: lecture 7 Database design
SQL: Constraints and Triggers
Module 5: Implementing Data Integrity by Using Constraints
CPSC-310 Database Systems
Introduction lecture1.
STRUCTURED QUERY LANGUAGE
The Relational Model Relational Data Model
SQL OVERVIEW DEFINING A SCHEMA
Geo-Databases: lecture 2 The Relational Data Model
Oracle Data Definition Language (DDL)
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Geo-Databases: lecture 5 Data Manipulation in SQL
Database Design: Relational Model
Geo-Databases: lecture 3 Simple Queries in SQL
Geo-Databases: lecture 4 Complex Queries in SQL
SQL – Constraints & Triggers
CPSC-608 Database Systems
Integrity 5/5/2019 See scm-intranet.
Relational Data Model - 2
Triggers 7/11/2019 See scm-intranet.
-Transactions in SQL -Constraints and Triggers
Presentation transcript:

Geo-Databases: lecture 6 Data Integrity Prof. Dr. Thomas H. Kolbe Institute for Geodesy and Geoinformation Science Technische Universität Berlin Credits: This material is mostly an english translation of the course module no. 8 (‘Geo-Datenbanksysteme‘) of the open e-content platform www.geoinformation.net.

Data Integrity 19/04/2019

Motivation “Invalid“ states must be avoided: real world A student is assigned the mark -6 (in Germany from 1 to 6). A lecture is assigned a nonexistent lecturer. A lecturer is neither assigned a lecture nor is he listed in the table “sabbatical semester“. real world real world‘ mini-world mini-world‘ Integrity constraints describe valid states of the system. Their compliance is controlled by the DBMS. 19/04/2019

Data Integrity – Methods presented so far Already mentioned methods for the definition of integrity constraints are: Specification of the value domain for each column: ZIP NUMERIC(5,0) A postal code (ZIP number) is allowed a maximum length of 5 digits (in Germany). Prohibition of NULL values: Name VARCHAR(30) NOT NULL Guarantees that no tuple will have a NULL entry in “Name“ (or vice-versa: every tuple must have a “Name“ value different from NULL) Primary key: Guarantees that there are no two tuples with identical key attributes No tuple is allowed the NULL value in a primary key attribute 19/04/2019

Referential Integrity - Motivation The constraint “Every lecture is held by a lecturer.“ is formally soecified wrt. the database as follows : For each tuple within Vorlesungen (lectures) there is a tuple within professors, such that Vorlesungen.PersNr = Professoren.PersNr In general: referential integrity foreign key integrity violation! foreign key Referential integrity cannot be guaranteed by the the previously introduced integrity constraints. 19/04/2019

Referential integrity in SQL (1) We need language constructs that can be used to introduce primary/foreign key relations to the system. CREATE TABLE Professoren (PersNr INTEGER PRIMARY KEY, ...); CREATE TABLE Vorlesungen (..., PersNr INTEGER, FOREIGN KEY(PersNr) REFERENCES Professoren(PersNr)); When to check? At the end of a data manipulation operation (default) At the end of a transaction Principle: The database is in a state of referential integrity before the manipulation Changes are only applied, if they are “valid“ The database is in a state of referential integrity after the manipulation 19/04/2019

Referential integrity in SQL (2) Default strategy: Rejection of invalid changes 2nd strategy: cascading changes CREATE TABLE Professoren (PersNr INTEGER PRIMARY KEY, ...); CREATE TABLE Vorlesungen (..., PersNr INTEGER, FOREIGN KEY(PersNr) REFERENCES Professoren (PersNr) ON DELETE CASCADE); foreign key foreign key foreign key …analogous ON UPDATE CASCADE for cascading UPDATE 19/04/2019

Referential integrity in SQL (3) 3. strategy: insertion of a default value Similar syntax to ON DELETE / UPDATE CASCADE: ON DELETE / UPDATE SET NULL: …on deletion / updating the foreign key is set to NULL ON DELETE / UPDATE SET DEFAULT: …on deletion / updating the foreign key is set to a default value 19/04/2019

CHECK Clause Allows additional constraints on the level of attributes and tables. Example: Graduates must have studied for at least 8 semesters CREATE TABLE Graduates  ( ..., Semester INTEGER CHECK Semester >= 8) CHECK conditions can be as complex as the WHERE conditions: Only Professors are allowed to hold an exam. CREATE TABLE Exams ( Name VARCHAR(30) NOT NULL, ... CHECK (Name IN (SELECT Name FROM Professoren)) Attention! The CHECK constraint is carried out only in case of data manipulations of the respective table (no checking if “Professoren“ is changed)! 19/04/2019

Outlook If an integrity constraint is not only to be checked on the change of a single table, it has to be formulated on the database schema level. In order to ensure integrity propagation of changes might become necessary. Assertions CREATE ASSERTION <name> CHECK <condition> <condition> like in the WHERE clause Check is performed on changes to any of the tables specified in <condition> Resolving of change propagations to ensure integrity (Trigger) User-defined procedures that are launched automatically if a certain condition is fulfilled Since SQL:1999 standardised For more details, see literature 19/04/2019

References Overview: Hector Garcia-Molina, Jeffrey D. Ullman, Database Systems: The Complete Book, Prentice Hall, 2002 Alfons Kemper, André Eickler, Datenbanksysteme - Eine Einführung, Oldenbourg Verlag, München, 1996 Jim Melton, Alan R. Simon, SQL 1999: Understanding Relational Language Components, Morgan Kaufmann Publishers, 2001 Gottfried Vossen, Datenbankmodelle; Datenbanksprachen und Datenbankmanagement-Systeme, Oldenbourg Verlag, München, 1999 19/04/2019