SlideServe
Menu
Préférences
© SlideServe · v2026

Constraints

josephgraham avatar
16 diapositives · 273 Views · Jan 02, 2020

Learn about the importance of triggers and constraints in SQL databases, including how to write trigger programs and apply constraints effectively. Explore examples and best practices for optimizing database operations.

Constraints - slide 1
01 / 16Constraints
1 / 17

Télécharger la présentation

Constraints
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Constraints Review

  2. What is a constraint? • Unique – forbids duplicate values • Referencial – Foreign key • Check Constraint – sets restrictions on data added to a specific table

  3. SQL vs ADDPFCST

  4. Database Triggers

  5. Trigger? • A condition that causes some procedure to be executed. • On the Iseries, a program that is called when a program tries to insert, update or delete a database record • A trigger can be more complex than a check constraint

  6. Writing Trigger Programs • Just as you do any HLL program • AddPFTrg (Add Physical File Trigger) to associate the program with the database file.

  7. 6 Trigger Conditions • Before Insert • Before Update • Before Delete • After Insert • After Update • After Delete

  8. Advantages • Be sure that the actions coded in the trigger program are executed irregardless of the application that is trying to modify the database

  9. Disadvantages • You must be aware that triggers exist

  10. RmvPfTrg • Removes a trigger program from a database

  11. Coding a Trigger Program • Can be coded in any iSeries HLL • Must have 2 parameters that conform to IBM-defined interface for trigger programs • Trigger buffer • Before and after image of the affected row • See Fig 16.1 in text book • Trigger length • Length of the buffer

  12. Trigger Program • Trigger Programs must cause an exception message. • Best way to do this is to send a program message to the calling program. • This causes the application to crash and the database update is halted.

  13. Vendor Master CREATE TABLE VENDOR (VENID DEC (7 , 0) NOT NULL WITH DEFAULT, NAME CHAR (30 ) NOT NULL WITH DEFAULT, MINORD DEC (7 , 0) NOT NULL WITH DEFAULT, CONSTRAINT VENDORPK PRIMARY KEY (VENID))

  14. Write a Trigger Program • Minimum order must be greater than 100.00

  15. Student Master CREATE TABLE STUDENT (STUDID NUMERIC (9 , 0), SNAME CHAR (30 ), PROV CHAR (15), ACTBAL NUMERIC(11, 2))

  16. Write a trigger program that will not allow records to be updated where the PROV = ON and the ACTBAL < 100