constraints & triggers - artificial...
TRANSCRIPT
![Page 1: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/1.jpg)
Jennifer Widom
Constraints & Triggers
Motivation and overview
![Page 2: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/2.jpg)
Jennifer Widom
Constraints & Triggers Constraints and Triggers
For relational databases
SQL standard; systems vary considerably
(Integrity) Constraints constrain allowable database states
Triggers
monitor database changes, check conditions and initiate actions
![Page 3: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/3.jpg)
Jennifer Widom
Constraints & Triggers Integrity Constraints Impose restrictions on allowable data, beyond those imposed by structure and types
Examples
![Page 4: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/4.jpg)
Jennifer Widom
Constraints & Triggers Integrity Constraints Impose restrictions on allowable data, beyond those imposed by structure and types
Why use them?
![Page 5: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/5.jpg)
Jennifer Widom
Constraints & Triggers Integrity Constraints Impose restrictions on allowable data, beyond those imposed by structure and types
Classification
![Page 6: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/6.jpg)
Jennifer Widom
Constraints & Triggers Declaring and enforcing constraints
Declaration
With original schema
Or later
Enforcement
Check after every modification
Deferred constraint checking
![Page 7: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/7.jpg)
Jennifer Widom
Constraints & Triggers Triggers “Event-Condition-Action Rules” When event occurs, check condition; if true, do action
Examples
![Page 8: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/8.jpg)
Jennifer Widom
Constraints & Triggers Triggers “Event-Condition-Action Rules” When event occurs, check condition; if true, do action
Why use them?
![Page 9: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/9.jpg)
Jennifer Widom
Constraints & Triggers Triggers in SQL “Event-Condition-Action Rules”
Create Trigger name Before|After|Instead Of events [ referencing-variables ]
[ For Each Row ]
When ( condition )
action
![Page 10: Constraints & Triggers - Artificial Intelligenceopenclassroom.stanford.edu/MainFolder/courses/cs...Integrity Constraints Impose restrictions on allowable data, beyond those imposed](https://reader034.vdocuments.net/reader034/viewer/2022052018/6031b9cf3ef2e7166b4bb33d/html5/thumbnails/10.jpg)
Jennifer Widom
Constraints & Triggers Constraints and Triggers
For relational databases
SQL standard; systems vary considerably
(Integrity) Constraints constrain allowable database states
Triggers
monitor database changes, check conditions and initiate actions