Deductive Databases General idea: some relations are stored (extensional), others are defined by datalog queries (intensional). Many research projects.

Slides:



Advertisements
Similar presentations
DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
Advertisements

1 Constraints, Triggers and Active Databases Chapter 9.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CSE 544 Constraints Lecture #3 Friday, January 13, 2011 Dan Suciu , Winter
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
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.
Chapter 7 Notes on Foreign Keys Local and Global Constraints Triggers.
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
Constraints and Triggers Foreign Keys Local and Global Constraints Triggers.
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
CMSC424: Database Design Instructor: Amol Deshpande
Winter 2002Arthur Keller – CS 1809–1 Schedule Today: Jan. 31 (TH) u Constraints. u Read Sections , Project Part 3 due. Feb. 5 (T) u Triggers,
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
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.
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.
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.
SQL Server 7.0 Maintaining Referential Integrity.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
RDBMSSection Relational DBMS DATABASE DEVELOPMENT And Franchise Colleges By MANSHA NAWAZ.
1 Lecture 6: Views Friday, January 17th, Updating Views How can I insert a tuple into a table that doesn’t exist? Employee(ssn, name, department,
1 SQL Constraints and Programming. 2 Agenda Constraints in SQL Systems aspects of SQL.
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.
ICS 321 Fall 2011 Constraints, Triggers, Views & Indexes Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
IST 210 Constraints and Triggers. IST Constraints and Triggers Constraint: relationship among data elements DBMS should enforce the 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.
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
1 Chapter 6 Constraints uForeign Keys uConstraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Constraints and Triggers. What’s IC? Integrity Constraints define the valid states of SQL-data by constraining the values in the base tables. –Restrictions.
Referential Integrity checks, Triggers and Assertions Examples from Chapter 7 of Database Systems: the Complete Book Garcia-Molina, Ullman, & Widom.
Advanced SQL Concepts - Checking of Constraints CIS 4301 Lecture Notes Lecture /6/2006.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
Session 1 Module 1: Introduction to Data Integrity
Constraining Attribute Values Constrain invalid values –NOT NULL –gender CHAR(1) CHECK (gender IN (‘F’, ‘M’)) –MovieName CHAR(30) CHECK (MovieName IN (SELECT.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
1 Lecture 06 Data Modeling: E/R Diagrams Wednesday, January 18, 2006.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
1 Introduction to Database Systems, CS420 SQL Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
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.
Chapter 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Getting started with Accurately Storing Data
Fundamental of Database Systems
Chapter 6: Integrity (and Security)
Constraints and Triggers
Foreign Keys Local and Global Constraints Triggers
CPSC-608 Database Systems
SQL: Constraints and Triggers
Referential Integrity
CPSC-310 Database Systems
2018, Fall Pusan National University Ki-Joune Li
The Relational Model Relational Data Model
Referential Integrity
SQL – Constraints & Triggers
CPSC-608 Database Systems
Lecture 05: SQL Wednesday, October 9, 2002.
Presentation transcript:

Deductive Databases General idea: some relations are stored (extensional), others are defined by datalog queries (intensional). Many research projects (MCC, Stanford, Wisconsin) [Great Ph.D theses!] SQL3 realized that recursion is useful, and added linear recursion. Hard problem: optimizing datalog performance. Ideas from ddb’s made it into practice (recursion, magic sets, pred. movearound).

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 properties Build handlers into the database definition\ Key constraints Referential integrity constraints.

Keys: Fundamental Constraint In the CREATE TABLE statement, use: –PRIMARY KEY, UNIQUE CREATE TABLE MovieStar ( name CHAR(30) PRIMARY KEY, address VARCHAR(255), gender CHAR(1)); Or, list at end of CREATE TABLE PRIMARY KEY (name)

Keys... Can use the UNIQUE keyword in same way –…but for any number of attributes –foreign key only reference PRIMARY KEY Indexing Keys CREATE UNIQUE INDEX YearIndex ON Movie(year) Makes insertions easier to check for key constraints Subtle differences between PRIMARY KEY and UNIQUE

Foreign Key Constraints ActedIn(ActorName, MovieName) Movies(MovieName, year) If MovieName in ActedIn is a foreign key for Movies, then: 1) Foreign Key must be a reference to a valid value in the referenced table. 2) … must be a PRIMARY KEY in the referenced table. Yes, this is a referential integrity constraint.

Declaring Foreign Key Constraints REFERENCES keyword... CREATE TABLE ActedIn ( Name CHAR(30) PRIMARY KEY, MovieName CHAR(30) REFERENCES Movies(MovieName)); Or, summarize at end of CREATE TABLE FOREIGN KEY MovieName REFERENCES Movies(MovieName) MovieName must be a PRIMARY KEY

How do we Maintain them? Given a change to DB, there are several possible violations: –Insert new tuple with bogus foreign key value –Update a tuple to a bogus foreign key value –Delete a tuple in the referenced table with the referenced foreign key value –Update a tuple in the referenced table that changes the referenced foreign key value

How to Maintain? Recall, ActedIn has FK MovieName... Movies(MovieName, year) (Fatal Attraction, 1987) ActedIn(ActorName, MovieName) (Michael Douglas, Fatal Attraction) insert: (Rick Moranis, Strange Brew)

How to Maintain? Policies for handling the change… –Reject the update (default) –Cascade (example: cascading deletes) –Set NULL Can set update and delete actions independently in CREATE TABLE MovieName CHAR(30) REFERENCES Movies(MovieName)) ON DELETE SET NULL ON UPDATE CASCADE

Midterm: BCNF Decompose R(A,B,C,D,E) with functional dependencies A  B, B  C, C  D into BCNF.

Midterm: SQL 1 For each book that has been both borrowed and requested, give the phone number of the borrower and the requester Select b.phone_number, r.phone_number From Library_Patron as b, Library_Patron as r, Book_Request as br, Borrowed as bo Where b.card_number = borrowers_card_number and r.card_number = requesters_card_number and bo.book_ISBN = br.book_ISBN

Midterm SQL: 2 How many times have books titled A First Course in Database Systems been borrowed? Select count(*) From Borrowed, Book Where Borrowed.book_ISBN = Book.ISBN And Book.title = ‘A First Course in Database Systems’

Midterm SQL: 3 The set of pairs (a, n), where n is the number of times that Alon Levy has borrowed a book authored by a. Select count(book_ISBN), author From Borrowed, Book, Library_Patron Where Borrowed.book_ISBN = Book.ISBN And Library_Patron.first_name = ‘Alon’ And Library_Patron.last_name = ‘Levy’ And Borrowed.borrowers_card_number = Library_Patron.card_number Group by author

Midterm SQL: 4 Give a SQL query that produces the set of pairs (borrower, number) such that "number" is the number of books borrowed by the "borrower" and that :  Each book has never been borrowed by someone else  The last name of the book's author is alphabetically after borrowers Select card_number, count(book_ISBN) From Library_patron, Borrowed, Book Where card_number = borrowers_card_number and author > last_name and book_ISBN = ISBN and book_ISBN not in ( Select book_ISBN From Borrowed as borrower1, Borrowed as borrower2, book Where book_ISBN = ISBN and Borrower1.borowers_card_number <>borower2.borrowers_card_number) Group by card_number