אילוצי שלמות אילוצי תחום מפתחות ומפתחות זרים טריגרים triggers

Slides:



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

Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Integrity Constraints.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity (and Security) Domain Constraints Referential Integrity Assertions Triggers.
C.1 Appendix C: Advanced Relational Database Design Reasoning with MVDs Higher normal forms Join dependencies and PJNF DKNF.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Appendix B: Advanced.
BRANCH-SCHEME (BRANCH-NAME, ASSETS, BRANCH-CITY)
SQL Sangeeta Devadiga CS157A, Fall Outline Background Data Definition Basic Structure Set Operation.
Integrity Constraints
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all account records at the Perryridge branch.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 7.
Functional Dependencies (Part 3) Presented by Nash Raghavan All page numbers are in reference to Database System Concepts (5 th Edition)
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 8.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
MySQL Tutorial (2) Introduction to Database. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city)
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 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
CS 370 Database Systems Lecture 13 Introduction to SQL.
Department of Computer Science and Engineering, HKUST Slide 1 Comp 231 Database Management Systems Comp 231 Database Management Systems 6. Integrity Constraints.
Chapter 4 Intermediate SQL: Integrity Constraints.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Chapter 5 Integrity Constraints 5.1 Domain ConstraintsDomain Constraints 5.2 Referential IntegrityReferential Integrity 5.3 AssertionsAssertions 5.4 TriggersTriggers.
Chapter 4: Advanced SQL. 4.2Unite International CollegeDatabase Management Systems Chapter 4: Advanced SQL SQL Data Types and Schemas Integrity Constraints.
Holliday - COEN 1781 Introduction to SQL. Holliday - COEN 1782 DB Tables and SQL The data is stored in the database in relations or tables Data types.
3.1 Chapter 3: SQL Schema used in examples p (omit 3.8.2, , 3.11)
Structured Query Language 2 Presented by: Annisa, M.Kom. Source: Database System Concepts 5 th edition.
Relational Model: Examples. Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account.
Relational Algebra Instructor: Mohamed Eltabakh 1.
-- Introduction to database principles Maoying Wu March 25, 2013 Chapter 4: Advanced SQL (1)
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all tuples from the loan relation. delete.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Relational.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)
Advanced SQL: Triggers & Assertions
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Appendix B: Advanced.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity Constraints Domain Constraints Referential Integrity Assertions Triggers.
Chapter 6: Integrity (and Security)
Insert, Update and the rest…
Relational Database Design
Relational Database Design by Dr. S. Sridhar, Ph. D
Structured Query Language (SQL)
Relational Database Design
Relational Database Design
Integrity Constraints
Referential Integrity
Chapter 3: SQL.
5-2-7 : تقسيم الصفوف في الجدول إلي مجموعات :-
Referential Integrity
Instructor: Mohamed Eltabakh
Introduction to SQL Holliday - COEN 178.
Appendix C: Advanced Normalization Theory
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: Mohamed Eltabakh
Relational Database Design
Appendix C: Advanced Relational Database Design
Chapter 28: Advanced Relational Database Design
Database.
Presentation transcript:

אילוצי שלמות אילוצי תחום מפתחות ומפתחות זרים טריגרים triggers תלויות פונקציונליות

אילוצי תחום Domain Constraints הגדרה של תחומי משתנים בתבניות יחסים מאפשרת לבדוק תקינות ערכים מוזנים לבה”נ וכן לבדוק תקינות של שאילתות. הגדרות תחום ב SQL char (n) bit (n) numeric (n,m) integer smallint real, double precision date time מחרוזת תווים אלפאנומריים באורך n. מחרוזת ביטים באורך n. מספר עשרוני בן n ספרות, מתוכן m אחרי הנקודה. מספר שלם, התופס מלת מחשב. מספר שלם התופס חצי מלת מחשב. ממשי, ממשי עם דיוק כפול. שדה היכול להכיל רק ערכים חוקיים של תאריך. שדה היכול להכיל רק ערכים חוקיים של שעה ביממה.

אילוצי שלמות קישור refernetial integrity constrints יהיו r וs יחסים עם תבניות R ו S שיש ביניהן תכונות משותפות. nיות בr שאינן מצטרפות בפעולת הצירוף הטבעי לאף nיה בs נקראות nיות מדולדלות (dangling). מפתח זר (foreign key) - תכונה או קבוצת תכונות בתבנית כלשהי המהווה מפתח קביל בתבנית אחרת.

הגדרת מפתחות ראשיים, קבילים וזרים ב SQL primary key unique key foreign key

אילוצים על ערכי דמה (null) תכונה שחייבת להכיל ערך קביל, מוכרזת כ not null. כל תכונה השייכת למפתח קביל כלשהו חייבות להיות מוכרזת כ not null.

הגדרה של חלק מתבניות מערכת הבנק create table customer (customer-name char(20) not null, street char(30), customer-city char(30), primary key (customer-name)) create table branch (branch-name char(15) not null, assets integer, branch-city char(30), primary key (branch-name)) create table deposit (branch-name char(15), account-number char(10) not null, customer-name char(20) not null, balance integer, primary key (account-number,customer-name), foreign key (branch-name) references branch, foreign key (customer-name) references customer ) הגדרה של חלק מתבניות מערכת הבנק

טריגרים triggers כללים המגדירים פעולות שיש לבצען באירועים מיוחדים. הטריגר חייב להגדיר: המאורע (מאורעות) המפעיל (מפעילים) את הכלל. התנאי שקובע אם יש לבצע את הפעולה. הפעולה בה יש לנקוט, בד"כ סדרת פעולות SQL. לדוגמא (התחביר סתמי) create trigger after update on deposit when (new.balance < 0) insert into borrow select branch_name, account_number, customer_name,-new.balance; update deposit set new.balance = 0;

תלויות פונקציונליות (functional dependencies) תלויות פונקציונליות הן אילוצים על היחסים החוקיים, ומהוות הכללה של המושג מפתח-על. תלות פונקציונלית - יהי r יחס בעל תבנית R . ויהיו  ו  תתי קבוצות של R. התלות הפונקציונלית מתקיימת על R אם לכל יחס חוקי (r(R , לכל זוג nיות t1,t2 ביחס r מתקיים  t1[]=t2[]  t1[]=t2[] (במלים אחרות, כל ערך של  קשור לערך יחיד של ).

אילו תלויות פונקציונליות מתקיימות על היחס הבא? תלות פונקציונלית טריוויאלית - ת”פ המתקיימת על כל יחס. למשל AA היא ת”פ טריוויאלית. באופן כללי, התלות הפונקציונלית  היא ת”פ טריוויאלית אם .

תלויות פונקציונליות במערכת הבנק Branch = (branch-name, assets, branch-city) branch-name branch-name, assets, branch-city Customer = (customer-name, street, customer-city) customer-name customer-name ,street, customer-city Borrow = (branch-name, loan-number, customer-name, amount) loan-number amount, branch-name Deposit=(branch-name, account-number, customer-name, balance) account-number  balance, branch-name

סגור של קבוצת תלויות פונקציונליות בהינתן קבוצה F של תלויות פונקציונליות החלות על תבנית R ניתן להוכיח כי יחולו על התבנית ת”פ נוספות. נאמר כי תלויות אלו נובעות לוגית מF. תהי F קבוצת תלויות פונקציונליות. הסגור של F המסומן +F היא אוסף התלויות הפונקציונליות הנובעות לוגית מF. שתי קבוצות של תלויות פונקציונליות F1 ו F2 הן שקולות לוגית אם F2+ = F1+

כללי ארמסטרונג Reflexivity rule: if  is a set of attributes and  then  holds. Augmentation rule: if  holds and  is a set of attributes then   holds. Transitivity rule: if  and   hold then   holds . כללים נוספים (ניתנים להסקה מכללי ארמסטרונג) Union rule: if  and  hold, then  holds. Decomposition rule: if  holds then   and   hold. Pseudotransitivity rule: if  and  hold then  holds .

סגור של קבוצת תכונות הסגור של קבוצת תכונות - תהי  קבוצה של תכונות. הסגור של  (סימון - +) הוא קבוצת כל התכונות, הנקבעות פונקציונלית על ידי  תחת קבוצה F של תלויות פונקציונליות. כלומר = {A| AR  A  F+} + אלגוריתם לחישוב של + result=  ; while (changes to result) { for (each f.d.   in F) if ( result) result=result   ; }

שימושים התלות הפונקציונלית  נובעת לוגית מ F (כלומר F+ ) אםם  + שתי קבוצות של תלויות פונקציונליות F1 ו F2 הן שקולות לוגית אםם לכל קבוצת תכונות  סגור זהה תחת F1 ו F2

חישוב מפתח קביל של תבנית אלגוריתם לחישוב מפתח קביל לתבנית R בהינתן קבוצת תלויות פונקציונליות החלות עליה result= R ; For (each attribute A in result) { compute (result – A)+ with respect to F; if (result – A)+ = R result = result – {A}; }

כיסוי קנוני תהי F קבוצה של תלויות פונקציונליות. תכונה A היא עודפת ב  אם קבוצת הת”פ נובעת לוגית מ F. תכונה A היא עודפת ב  אם F נובעת לוגית מ F-{}  {( - A) } F-{}  {  ( - A) }

תהי F קבוצה של תלויות פונקציונליות תהי F קבוצה של תלויות פונקציונליות. כיסוי קנוני Fc של F היא קבוצה של תלויות פונקציונליות השקולה לוגית ל F (כלומר כל התלויות הפונקציונליות ב F נובעות לוגית מ Fc ולהיפך). המקיימת את שתי התכונות הבאות: אין ב Fc תלויות פונקציונליות הכוללות תכונות עודפות. לכל תלות פונקציונלית ב Fc אגף שמאל ייחודי. ההגדרה הנ"ל משרה אלגוריתם לחישוב של Fc . (קיימות בספרות הגדרות שונות במקצת לכיסוי הקנוני. בסופו של דבר לצרכים מעשיים ההגדרות הללו שקולות).

חישוב כיסוי קנוני Fc אלגוריתם לחישוב כיסוי קנוני בהינתן קבוצת תלויות פונקציונליות F result= F ; For each f.d.  in result For each attribute A in  if A is extraneous (ODEF) delete it from  Use Union rule to replace each two f.d.’s in result having the same LHS, 1 and 2 , by a single f.d. 1 2 Remove trivial f.d’s