SlideShare a Scribd company logo
1 of 12
Download to read offline
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

More Related Content

What's hot

Database User and Administrator
Database User and AdministratorDatabase User and Administrator
Database User and AdministratorA. S. M. Shafi
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocolBBDITM LUCKNOW
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data miningkavitha muneeshwaran
 
Advanced Structural Modeling
Advanced Structural ModelingAdvanced Structural Modeling
Advanced Structural ModelingAMITJain879
 
DBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsDBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsBHARATH KUMAR
 
Query optimization
Query optimizationQuery optimization
Query optimizationPooja Dixit
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMSkoolkampus
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database DesignArchit Saxena
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraintsmadhav bansal
 
Structure of dbms
Structure of dbmsStructure of dbms
Structure of dbmsMegha yadav
 

What's hot (20)

Relational model
Relational modelRelational model
Relational model
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
Database User and Administrator
Database User and AdministratorDatabase User and Administrator
Database User and Administrator
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data mining
 
Advanced Structural Modeling
Advanced Structural ModelingAdvanced Structural Modeling
Advanced Structural Modeling
 
DBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsDBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL Commands
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
Triggers
TriggersTriggers
Triggers
 
View of data DBMS
View of data DBMSView of data DBMS
View of data DBMS
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 
Cohesion and coupling
Cohesion and couplingCohesion and coupling
Cohesion and coupling
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
 
NESTED SUBQUERY.pptx
NESTED SUBQUERY.pptxNESTED SUBQUERY.pptx
NESTED SUBQUERY.pptx
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Data models
Data modelsData models
Data models
 
Structure of dbms
Structure of dbmsStructure of dbms
Structure of dbms
 
Query processing
Query processingQuery processing
Query processing
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 

Similar to 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
 
[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
 
Final ProjectBe sure to follow the instructions for each step as.docx
Final ProjectBe sure to follow the instructions for each step as.docxFinal ProjectBe sure to follow the instructions for each step as.docx
Final ProjectBe sure to follow the instructions for each step as.docxvoversbyobersby
 

Similar to 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
 
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
 
Final ProjectBe sure to follow the instructions for each step as.docx
Final ProjectBe sure to follow the instructions for each step as.docxFinal ProjectBe sure to follow the instructions for each step as.docx
Final ProjectBe sure to follow the instructions for each step as.docx
 

Recently uploaded

Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxpriyankatabhane
 
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxTHE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxNandakishor Bhaurao Deshmukh
 
Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trssuser06f238
 
Sulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptx
Sulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptxSulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptx
Sulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptxnoordubaliya2003
 
Pests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdfPests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdfPirithiRaju
 
Environmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial BiosensorEnvironmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial Biosensorsonawaneprad
 
The dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptxThe dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptxEran Akiva Sinbar
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRlizamodels9
 
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdfBUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdfWildaNurAmalia2
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.PraveenaKalaiselvan1
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfSELF-EXPLANATORY
 
preservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptxpreservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptxnoordubaliya2003
 
Microteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical EngineeringMicroteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical EngineeringPrajakta Shinde
 
Citronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyayCitronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyayupadhyaymani499
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxRESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxFarihaAbdulRasheed
 

Recently uploaded (20)

Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptx
 
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxTHE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
 
Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 tr
 
Sulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptx
Sulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptxSulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptx
Sulphur & Phosphrus Cycle PowerPoint Presentation (2) [Autosaved]-3-1.pptx
 
Pests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdfPests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdf
 
Environmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial BiosensorEnvironmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial Biosensor
 
The dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptxThe dark energy paradox leads to a new structure of spacetime.pptx
The dark energy paradox leads to a new structure of spacetime.pptx
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
 
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdfBUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
 
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort ServiceHot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
 
preservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptxpreservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptx
 
Microteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical EngineeringMicroteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical Engineering
 
Citronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyayCitronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyay
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxRESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
 

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.