SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
ACTIVE DATABASE TRIGGER
PRESENTED BY
S.BALAMURUGAN
ASST.PROFESSOR
DEPT OF COMPUTER SCIENCE
SBK COLLEGE ,ARUPPUKOTTAI
TRIGGERS AND ACTIVE
DATABASE
 A triggers is a procedure that is automatically invoked by
the DBMS in responds to specified change to the
database, and is typically specified by the DBA.
 A data base that has a set of associated triggers is called
an active database.
 ATRIGGERS DESCRIPTION CONTAINSTHREE PARTS
 Event:
A change to the database that activates the triggers.
 Condition:
A query or test is run when the triggers is activate.
 Action:
A procedure that is executed when the trigger is
activated and its condition is true.
 The event specification an insert , delete , or update
statement.
 A condition in a trigger can be a true/false statement.
e.g., ( All employee salaries are less
than($100,000) or query is interrupted as true if
the answer set is nonempty and false if the query
has no answer. If the condition part evaluates to
true, the action associated with trigger is
executed
 Activating the trigger, executed new queries and make changes to
the database.
 An action can even execute a series of data-definition commands
e.g., (create new tables, change authorization) and
transaction-oriented commands. e.g.,(commit) or call host-
language procedures.
EXAMPLE OFTRIGGERS
 A trigger action can answer to the query in the condition part of
the trigger, refer to old and new values of tuple modified by the
statement
For example,
we have to examine the age field of the inserted student
record to decide whether to increment the count, trigger.
CREATE TRIGGER init_count BEFORE INSERT ON STUDENT /*Event*/
DECLARE
count INTEGER;
BEGIN /*Action*/
count :=0;
END
CREATETIGGER incr_count AFTER INSERT ON student /*Event/
WHEN (new. age < 18) /* condition ; ‘new’ is just-inserted tuple*/
FOR EACH ROW
BEGIN /* Action; a procedure in oracle’s PL/SQL syntax*/
count :=count+1;
END
 Ing event should be defined to occur for each modified
record; the for EACH ROW clause is used to do this.
 Such a trigger is called a row-level trigger.
 the init-count trigger is executed just once per (INSERT
statement , regardless of the number of records inserted
, because we have omitted the FOR EACH ROW phrase.
 such a trigger is called a statement-level trigger.
 The keyword clause NEWTABLE enables us give a table
name (InsertedTuples) to the set of newly inserted
tuples.
 The FOR EACH STATEMENT clause specifies a statement
–level trigger and can be omitted because it is the
default.
 The definition does not have aWHEN clause ;if such
clause is included it follows the FOR EACH STATEMENT
clause , just before the Action specification.
 The trigger is evaluated once for each SQL statement the
insert tuples into students and inserts a single tuples into
a table that contains statistics on modification.
For example,
CREATETRIGGER set_countAFTER INSERT on student
/*Event/ REFERENCING NEWTABLE AS Inserted
Tuples
FOR EACH STATEMENT
INSERT /*Action/
INTO statistics table (modified table , modification type , count)
SELECT students ‘insert', count *
FROM inserted tuples I
WHERE I . age<18
DESINGNING ACTIVE DATABASES
 Triggers offers a powerful mechanism for dealing with
changes to database.
WHY TRIGGERS CAN BE HARD TO
UNDERSTAND
 The DBMS processes the trigger by evaluating its
condition part , and then(if the condition evaluates to
true) executing its action part.
 An important point is that the execution of the action
part of a trigger could in turn activate another trigger.
 In particular , the execution of the action part of a trigger
could again activate the same trigger , such triggers are
called recursive triggers.
CONSTRAINTS VERSUS TRIGGERS
 A constraints also prevents the data from being made
inconsistent by any kind of statement , whereas a trigger
is activated by a specific kind of
statement(INSERT,DELETE,UPDATE).
 Again , this restriction makes a constraints easier to
understand.
 Once the other hand trigger allow as to maintain
database integrity in more flexible ways ,as the follows
examples illustrate.
 Suppose that we have a table called ordered with fields
iternid , quantity , custom rid and unit prize.
 When a customer place on order , the first the three
fields value are filled in by the user(in this example, a
sales clerk).
 The fourth’s fields values can be obtained table to called
to items.
 But, it important to include it in the orders table to have
a complete record of the order ,in case the price of the
items is subsequently changed.
 We can define a trigger to look up this value and include
it in the fourth fields of a newly inserted record.
 Continuing with this example , we may want to perform
some additional action when an orders received.
For example,
if the purchase is being charged to a credit line
issued bye the company , we may want to check whether
the total cost of the purchase is within the current credit
limit.
 We can use trigger to do the check; indeed, we can
even use a CHECK constraints .
OTHERS USES OF TRIGGERS
 Triggers can generate a log of event to support auditing
and security checks.
for example,
each time a customer places an order , we can
create a record with the customer’s ID and current credit
limit and insert this record in a customer history table.
THANK U

Weitere Àhnliche Inhalte

Was ist angesagt?

Data Designs (Software Engg.)
Data Designs (Software Engg.)Data Designs (Software Engg.)
Data Designs (Software Engg.)Arun Shukla
 
joins in database
 joins in database joins in database
joins in databaseSultan Arshad
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational modelChirag vasava
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbmsSaranya Natarajan
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra pptGirdharRatne
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesionSutha31
 
Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational CalculusAmiya9439793168
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static ModelingSaurabh Kumar
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJDharita Chokshi
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts Bharat Kalia
 
Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)Ravinder Kamboj
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database conceptsTemesgenthanks
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
File organization 1
File organization 1File organization 1
File organization 1Rupali Rana
 

Was ist angesagt? (20)

Data Designs (Software Engg.)
Data Designs (Software Engg.)Data Designs (Software Engg.)
Data Designs (Software Engg.)
 
joins in database
 joins in database joins in database
joins in database
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
 
Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational Calculus
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static Modeling
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
File organization 1
File organization 1File organization 1
File organization 1
 

Ähnlich wie Triggers and active database

Mca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementMca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementRai University
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Thuan Nguyen
 
Database Triggers
Database TriggersDatabase Triggers
Database TriggersAliya Saldanha
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11AnusAhmad
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Thuan Nguyen
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15Syed Asrarali
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersAlexey Furmanov
 
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql databaseKimera Richard
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)Ehtisham Ali
 
Lab07_Triggers.pptx
Lab07_Triggers.pptxLab07_Triggers.pptx
Lab07_Triggers.pptxKhngNguyn81
 
Meters in IBM Maximo Asset Management
Meters in IBM Maximo Asset ManagementMeters in IBM Maximo Asset Management
Meters in IBM Maximo Asset ManagementRobert Zientara
 
Change tracking
Change trackingChange tracking
Change trackingSonny56
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 
pl/sql Procedure
pl/sql Procedurepl/sql Procedure
pl/sql ProcedurePooja Dixit
 

Ähnlich wie Triggers and active database (20)

Mca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementMca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction management
 
Triggers
TriggersTriggers
Triggers
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML Triggers
 
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql database
 
Trigger in mysql
Trigger in mysqlTrigger in mysql
Trigger in mysql
 
Trigger
TriggerTrigger
Trigger
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)
 
Lab07_Triggers.pptx
Lab07_Triggers.pptxLab07_Triggers.pptx
Lab07_Triggers.pptx
 
Meters in IBM Maximo Asset Management
Meters in IBM Maximo Asset ManagementMeters in IBM Maximo Asset Management
Meters in IBM Maximo Asset Management
 
Triggers.PPTX
Triggers.PPTXTriggers.PPTX
Triggers.PPTX
 
Change tracking
Change trackingChange tracking
Change tracking
 
Sql transacation
Sql transacationSql transacation
Sql transacation
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
pl/sql Procedure
pl/sql Procedurepl/sql Procedure
pl/sql Procedure
 

KĂŒrzlich hochgeladen

fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyDrAnita Sharma
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfSumit Kumar yadav
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxAArockiyaNisha
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSĂ©rgio Sacani
 
Stunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCRDelhi Call girls
 
CALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service đŸȘĄ
CALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  đŸȘĄCALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  đŸȘĄ
CALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service đŸȘĄanilsa9823
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...SĂ©rgio Sacani
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfrohankumarsinghrore1
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)Areesha Ahmad
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSĂ©rgio Sacani
 

KĂŒrzlich hochgeladen (20)

fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomology
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Stunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➄8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
CALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service đŸȘĄ
CALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  đŸȘĄCALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  đŸȘĄ
CALL ON ➄8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service đŸȘĄ
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 

Triggers and active database

  • 1. ACTIVE DATABASE TRIGGER PRESENTED BY S.BALAMURUGAN ASST.PROFESSOR DEPT OF COMPUTER SCIENCE SBK COLLEGE ,ARUPPUKOTTAI
  • 2. TRIGGERS AND ACTIVE DATABASE  A triggers is a procedure that is automatically invoked by the DBMS in responds to specified change to the database, and is typically specified by the DBA.  A data base that has a set of associated triggers is called an active database.  ATRIGGERS DESCRIPTION CONTAINSTHREE PARTS  Event: A change to the database that activates the triggers.  Condition: A query or test is run when the triggers is activate.
  • 3.  Action: A procedure that is executed when the trigger is activated and its condition is true.  The event specification an insert , delete , or update statement.  A condition in a trigger can be a true/false statement. e.g., ( All employee salaries are less than($100,000) or query is interrupted as true if the answer set is nonempty and false if the query has no answer. If the condition part evaluates to true, the action associated with trigger is executed
  • 4.  Activating the trigger, executed new queries and make changes to the database.  An action can even execute a series of data-definition commands e.g., (create new tables, change authorization) and transaction-oriented commands. e.g.,(commit) or call host- language procedures. EXAMPLE OFTRIGGERS  A trigger action can answer to the query in the condition part of the trigger, refer to old and new values of tuple modified by the statement For example, we have to examine the age field of the inserted student record to decide whether to increment the count, trigger. CREATE TRIGGER init_count BEFORE INSERT ON STUDENT /*Event*/ DECLARE count INTEGER; BEGIN /*Action*/ count :=0; END
  • 5. CREATETIGGER incr_count AFTER INSERT ON student /*Event/ WHEN (new. age < 18) /* condition ; ‘new’ is just-inserted tuple*/ FOR EACH ROW BEGIN /* Action; a procedure in oracle’s PL/SQL syntax*/ count :=count+1; END  Ing event should be defined to occur for each modified record; the for EACH ROW clause is used to do this.  Such a trigger is called a row-level trigger.  the init-count trigger is executed just once per (INSERT statement , regardless of the number of records inserted , because we have omitted the FOR EACH ROW phrase.
  • 6.  such a trigger is called a statement-level trigger.  The keyword clause NEWTABLE enables us give a table name (InsertedTuples) to the set of newly inserted tuples.  The FOR EACH STATEMENT clause specifies a statement –level trigger and can be omitted because it is the default.  The definition does not have aWHEN clause ;if such clause is included it follows the FOR EACH STATEMENT clause , just before the Action specification.  The trigger is evaluated once for each SQL statement the insert tuples into students and inserts a single tuples into a table that contains statistics on modification.
  • 7. For example, CREATETRIGGER set_countAFTER INSERT on student /*Event/ REFERENCING NEWTABLE AS Inserted Tuples FOR EACH STATEMENT INSERT /*Action/ INTO statistics table (modified table , modification type , count) SELECT students ‘insert', count * FROM inserted tuples I WHERE I . age<18 DESINGNING ACTIVE DATABASES  Triggers offers a powerful mechanism for dealing with changes to database.
  • 8. WHY TRIGGERS CAN BE HARD TO UNDERSTAND  The DBMS processes the trigger by evaluating its condition part , and then(if the condition evaluates to true) executing its action part.  An important point is that the execution of the action part of a trigger could in turn activate another trigger.  In particular , the execution of the action part of a trigger could again activate the same trigger , such triggers are called recursive triggers.
  • 9. CONSTRAINTS VERSUS TRIGGERS  A constraints also prevents the data from being made inconsistent by any kind of statement , whereas a trigger is activated by a specific kind of statement(INSERT,DELETE,UPDATE).  Again , this restriction makes a constraints easier to understand.  Once the other hand trigger allow as to maintain database integrity in more flexible ways ,as the follows examples illustrate.  Suppose that we have a table called ordered with fields iternid , quantity , custom rid and unit prize.  When a customer place on order , the first the three fields value are filled in by the user(in this example, a sales clerk).
  • 10.  The fourth’s fields values can be obtained table to called to items.  But, it important to include it in the orders table to have a complete record of the order ,in case the price of the items is subsequently changed.  We can define a trigger to look up this value and include it in the fourth fields of a newly inserted record.  Continuing with this example , we may want to perform some additional action when an orders received. For example, if the purchase is being charged to a credit line issued bye the company , we may want to check whether the total cost of the purchase is within the current credit limit.  We can use trigger to do the check; indeed, we can even use a CHECK constraints .
  • 11. OTHERS USES OF TRIGGERS  Triggers can generate a log of event to support auditing and security checks. for example, each time a customer places an order , we can create a record with the customer’s ID and current credit limit and insert this record in a customer history table.