SlideShare a Scribd company logo
Stored Procedure & Triggers
Tharindu Weerasinghe
www.tharinduweerasinghe.com
l
* A stored procedure is a segment of declarative SQL statements stored
inside the database catalog. (directory of information in database).
* A stored procedure can be invoked by triggers, other stored procedures,
and programming languages in the likes of Java, Python, PHP.
Stored Procedures
Stored Procedures (contd.)
l
Advantages of Stored Procedures
* Increase the performance of applications.
* Reduce traffic between the application and database
server.
* Reusable and transparent to all applications that access
the particular database.
* Secure.
l
Disadvantages of Stored Procedures
* If there are many procedures, the memory consumption
will be high and the overall system might stuck!
* Can't implement complex business logics.
* Not easy to maintain.
* Hard to debug the stored procedures.
A sample – Initial Setup
I aussume you all have a mysql user in your lab.
mysql -u username -p
If you know the root password let's login as root
mysql -u root -p 
CREATE DATABASE dbname;
USE dbname;
These things you should know by now as you should have done
these in your previous course. So our dbname is dblessons;
A sample – Initial Setup
I aussume you all have a mysql user in your lab.
mysql -u username -p
If you know the root password let's login as root
mysql -u root -p 
CREATE DATABASE dbname;
USE dbname;
These things you should know by now as you should have done
these in your previous course. So our dbname is dblessons;
A sample – Create Tables
CREATE TABLE `inventory` (
  `seqid` int(20) NOT NULL 
AUTO_INCREMENT,
  `itemtype` varchar(300) NOT NULL,
  `itemname` text NOT NULL,
  `itemid` varchar(20) NOT NULL,
  `usedby` int(10) DEFAULT NULL,
  PRIMARY KEY (`seqid`),
  UNIQUE KEY `itemid` (`itemid`)
) ENGINE=InnoDB AUTO_INCREMENT=123 
DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = 
@saved_cs_client */;
CREATE TABLE `employees` (
  `empid` int(10) unsigned NOT NULL,
  `name` varchar(300) NOT NULL,
  `homeaddress` text NOT NULL,
  `email` varchar(200) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `salary` varchar(20) NOT NULL,
  `joineddate` varchar(25) NOT NULL,
  `lastincrementdate` varchar(25) 
NOT NULL,
  `dateofbirth` varchar(25) NOT 
NULL,
  `designation` varchar(30) NOT 
NULL,
  `leaves` int(11) DEFAULT NULL,
  `resigneddate` varchar(25) DEFAULT 
NULL,
  `expertise` varchar(75) DEFAULT 
NULL,
  `nic` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`empid`)
) ENGINE=InnoDB DEFAULT 
CHARSET=latin1;
A sample – Insert Some Records
INSERT INTO `employees` VALUES(1,'Nimal Shantha','No.1, rnGood 
Road,rnNugegoda.',' ­',' ­ ','LKR 100,000.00','2014­10­03','2014­10­
10','1981­11­23','Manager',0,'2015­03­05',NULL,NULL),
(2,'Ruwan Darshana','No.1, rnFine 
Road,rnNugegoda','ruwan@abc.com','777101010','200,000','2014­10­03','2016­
01­15','1983­02­16','Head of Operations',24,'','Management, C++, Core Java, 
Python, Node JS','840141615V');
INSERT INTO `inventory` VALUES (1,'Laptop','NXMLZ0F8BE3400 (Adapter­
F210821437003201)','LP001',23),(2,'Laptop','NXMCAS01010847600 (Adapter­
F5TB0429143195)','LP002',20),(4,'Laptop','D499B12 (Adapter­CN­06TM1C­72438­
45K­2D6C­A01)','LP003',21),(9,'Laptop','NXG3HSG10E57E7600 (Adapter­
KP06503013548084D6PE03)','LP004',22),(11,'Laptop','NXMLZSG0F8DB3400 
(Adapter­F210821438001685)','LP005',16),(12,'Laptop','NXM24440F8563400 
(Adapter­ADT KP06503013548F883EPE03)','LP006',27);
DELIMITER <any character(s) you like, e.g. *> 
CREATE PROCEDURE item_type (IN item 
VARCHAR(20))
 
BEGIN   SELECT *  FROM inventory WHERE 
itemtype  = item; 
END <the above delimiter, which is *> 
A sample – Create a Procedure
(MySQL, MariaDB)
A sample – Call and See a Procedure
(MySQL, MariaDB)
Calling the created procedure:
CALL item_type(“Laptop”); 
<DELIMITER value declared above, which 
is *>
See the created procedure:
SHOW CREATE PROCEDURE 
item_type; <DELIMITER value 
declared above, which is *>
A sample – Complex Procedure –
Try something like these!
CREATE PROCEDURE
  Withdraw                             /* 
Routine name */
  (parameter_amount DECIMAL(6,2),     /* 
Parameter list */
  parameter_teller_id INTEGER,
  parameter_customer_id INTEGER)
  MODIFIES SQL DATA                   /* 
Data access clause */
  BEGIN                        /* Routine 
body */
    UPDATE Customers
        SET balance = balance ­ 
parameter_amount
        WHERE customer_id = 
parameter_customer_id;
    UPDATE Tellers
        SET cash_on_hand = cash_on_hand + 
parameter_amount
        WHERE teller_id = 
parameter_teller_id;
    INSERT INTO Transactions VALUES (
        parameter_customer_id,
        parameter_teller_id,
        parameter_amount);
  END;
Database Triggers
* A SQL trigger is a set of SQL statements
stored in the database catalog.
* A SQL trigger is run (or we say fired)
whenever an associated event
(with a) table occurs
e.g.,  insert, update or   delete.
l
Advantages of Triggers
* Can check errors in the business logic in the db layer.
* Provide an alternative way to check data integrity.
* Useful to audit the changes of data in tables.
l
Disdvantages of Triggers
* Triggers can only provide an extended validation and they cannot do all
the validations. Some basic validations have to be done in the application
layer.
e.g. you can validate user’s inputs in the client side by using JavaScript or on the
server side using server-side scripting languages such as JSP, PHP, ASP.NET, Perl.
* May increase the overhead of the db.
* Triggers are invoked and executed invisible from the client applications,
therefore, it is difficult to figure out what happens in the database layer.
A sample – Trigger, related to a db log
(first create 2 tables)
CREATE TABLE `projects` (
  `projid` varchar(20) NOT NULL,
  `projname` varchar(30) NOT NULL,
  `starteddate` varchar(25) NOT NULL,
  `currentstatus` varchar(25) NOT NULL,
  `projinfo` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`projid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE project_audit (
    id INT AUTO_INCREMENT PRIMARY 
KEY,
    projid VARCHAR(50) NOT NULL,
    projname VARCHAR(50) NOT NULL,
    currentstatus  VARCHAR(50)NOT 
NULL,
    action VARCHAR(50) DEFAULT 
NULL,
    changedat DATETIME DEFAULT 
NULL
);
A sample – Now Create the Trigger
DELIMITER $$$
CREATE TRIGGER after_project_update 
    AFTER UPDATE ON projects
    FOR EACH ROW 
BEGIN
    INSERT INTO project_audit
    SET action = 'update',
     projid = OLD.projid,
     projname = OLD.projname,
     changedat = NOW(); 
END $$$
DELIMITER;
This will list down all triggers you have created:
SHOW TRIGGERS; $$$ 
A sample – Trigger, related to a db log
(secondly enter some values to the projects table)
LOCK TABLES `projects` WRITE;
/*!40000 ALTER TABLE `projects` DISABLE KEYS */;
INSERT INTO `projects` VALUES
 ('Centralized','ERPCentralized','2016­11­21','In­
Progress','  Enterprise Version of ERPC'),
('ERPC','ERPC PHP','2016­10­02','In­Progress','Aimed 
for Customers'),('Tree­ECOn','Tree ECOn','2015­02­
13','On­Hold','  Tree STB ­ ECO');
/*!40000 ALTER TABLE `projects` ENABLE KEYS */;
UNLOCK TABLES;
A sample – Now Create the Trigger
DELIMITER $$$
CREATE TRIGGER after_project_update 
    AFTER UPDATE ON projects
    FOR EACH ROW 
BEGIN
    INSERT INTO project_audit
    SET action = 'update',
     projid = OLD.projid,
     projname = OLD.projname,
     changedat = NOW(); 
END $$$
DELIMITER;
This will list down all triggers you have created:
SHOW TRIGGERS; $$$ 
l
How to check the above Trigger?
We created a trigger that will execute after an update.
Hence we need to update the project table first.
UPDATE projects SET projname 
= "Fruit ECOn" WHERE projid = 
"Tree­ECOn"; $$$
Remember our delimiter this time is, $$$
Now, if you check your project_audit table then you will
see a new record being added.
l
How to check the above Trigger?
(contd.)
So what are the triggering options?
BEFORE INSERT – activated before data is inserted into the table.
AFTER INSERT – activated after data is inserted into the table.
BEFORE UPDATE – activated before data in the table is updated.
AFTER UPDATE – activated after data in the table is updated.
BEFORE DELETE – activated before data is removed from the table.
AFTER DELETE – activated after data is removed from the table.
Do more examples guys! Play with these! Enjoy triggering!
Gratitude
References:
http://www.mysqltutorial.org/introduction-to-sql-stored-procedures.aspx
https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-stored-procedures.html
http://www.mysqltutorial.org/sql-triggers.aspx
https://searchsqlserver.techtarget.com/definition/catalog
http://www.mysqltutorial.org/sql-triggers.aspx
https://mariadb.com/kb/en/library/stored-procedure-overview/
http://www.mysqltutorial.org/create-the-first-trigger-in-mysql.aspx
http://www.mysqltutorial.org/mysql-trigger-implementation.aspx

More Related Content

What's hot

javascript objects
javascript objectsjavascript objects
javascript objects
Vijay Kalyan
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
SQL
SQLSQL
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
Salman Memon
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
Ankit Dubey
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
Amrit Kaur
 
MySQL ppt
MySQL ppt MySQL ppt
MySQL ppt
AtharvaSawant10
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
11. transaction sql
11. transaction sql11. transaction sql
11. transaction sqlUmang Gupta
 

What's hot (20)

javascript objects
javascript objectsjavascript objects
javascript objects
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Js ppt
Js pptJs ppt
Js ppt
 
SQL Server Stored procedures
SQL Server Stored proceduresSQL Server Stored procedures
SQL Server Stored procedures
 
SQL
SQLSQL
SQL
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
MySQL ppt
MySQL ppt MySQL ppt
MySQL ppt
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
11. transaction sql
11. transaction sql11. transaction sql
11. transaction sql
 

Similar to Triggers and Stored Procedures

Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
Amit Kumar Singh
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republicKaing Menglieng
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
Dushyant Nasit
 
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
Ontico
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
Ehtisham Ali
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
Knoldus Inc.
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLJerry Yang
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
ftz 420
 
PyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorialPyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorial
jbellis
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
John Coonen
 
Subqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsSubqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsmaxpane
 

Similar to Triggers and Stored Procedures (20)

Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Python database access
Python database accessPython database access
Python database access
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
PyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorialPyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorial
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
Subqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsSubqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactions
 

More from Tharindu Weerasinghe

C Propgramming.pdf
C Propgramming.pdfC Propgramming.pdf
C Propgramming.pdf
Tharindu Weerasinghe
 
Basics of Computer Networks in Sinhala
Basics of Computer Networks in SinhalaBasics of Computer Networks in Sinhala
Basics of Computer Networks in Sinhala
Tharindu Weerasinghe
 
Data Structures & Algorithms in Sinhala
Data Structures & Algorithms in SinhalaData Structures & Algorithms in Sinhala
Data Structures & Algorithms in Sinhala
Tharindu Weerasinghe
 
Object Oriended Programming in Sinhala
Object Oriended Programming in Sinhala Object Oriended Programming in Sinhala
Object Oriended Programming in Sinhala
Tharindu Weerasinghe
 
Tips For A Better Undergraduate Research
Tips For A Better Undergraduate ResearchTips For A Better Undergraduate Research
Tips For A Better Undergraduate Research
Tharindu Weerasinghe
 
Basics of Block Chain
Basics of Block ChainBasics of Block Chain
Basics of Block Chain
Tharindu Weerasinghe
 
Basics of IoT
Basics of IoTBasics of IoT
Basics of IoT
Tharindu Weerasinghe
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
Tharindu Weerasinghe
 
Cloud Conputing Basics and some Related Research Topics
Cloud Conputing Basics and some Related Research TopicsCloud Conputing Basics and some Related Research Topics
Cloud Conputing Basics and some Related Research Topics
Tharindu Weerasinghe
 
Basic Concepts and Trends in Emerging Technologies
Basic Concepts and Trends in Emerging TechnologiesBasic Concepts and Trends in Emerging Technologies
Basic Concepts and Trends in Emerging Technologies
Tharindu Weerasinghe
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
Tharindu Weerasinghe
 
Introduction to Enterprise Applications and Tools
Introduction to Enterprise Applications and ToolsIntroduction to Enterprise Applications and Tools
Introduction to Enterprise Applications and Tools
Tharindu Weerasinghe
 
Introduction to Agile Software Development & Python
Introduction to Agile Software Development & PythonIntroduction to Agile Software Development & Python
Introduction to Agile Software Development & Python
Tharindu Weerasinghe
 
Agile Languages for Rapid Prototyping
Agile Languages for Rapid PrototypingAgile Languages for Rapid Prototyping
Agile Languages for Rapid Prototyping
Tharindu Weerasinghe
 
Things to ponder before you start building [cooperate] software
Things to ponder before you start building [cooperate] softwareThings to ponder before you start building [cooperate] software
Things to ponder before you start building [cooperate] software
Tharindu Weerasinghe
 
How to make screens and the internet safe for Children
How to make screens and the internet safe for Children How to make screens and the internet safe for Children
How to make screens and the internet safe for Children
Tharindu Weerasinghe
 
Different Concepts on Databases
Different Concepts on DatabasesDifferent Concepts on Databases
Different Concepts on Databases
Tharindu Weerasinghe
 
A Survey Study on Higher Education Trends among Sri Lankan IT Professionals
A Survey Study on Higher Education Trends among Sri Lankan IT ProfessionalsA Survey Study on Higher Education Trends among Sri Lankan IT Professionals
A Survey Study on Higher Education Trends among Sri Lankan IT Professionals
Tharindu Weerasinghe
 
A Survey Study on Higher Education Trends among Information Technology Prof...
A Survey Study  on  Higher Education Trends among Information Technology Prof...A Survey Study  on  Higher Education Trends among Information Technology Prof...
A Survey Study on Higher Education Trends among Information Technology Prof...
Tharindu Weerasinghe
 
Professionalism and Industry Expectations related to IT industry
Professionalism and Industry Expectations related to IT industry  Professionalism and Industry Expectations related to IT industry
Professionalism and Industry Expectations related to IT industry
Tharindu Weerasinghe
 

More from Tharindu Weerasinghe (20)

C Propgramming.pdf
C Propgramming.pdfC Propgramming.pdf
C Propgramming.pdf
 
Basics of Computer Networks in Sinhala
Basics of Computer Networks in SinhalaBasics of Computer Networks in Sinhala
Basics of Computer Networks in Sinhala
 
Data Structures & Algorithms in Sinhala
Data Structures & Algorithms in SinhalaData Structures & Algorithms in Sinhala
Data Structures & Algorithms in Sinhala
 
Object Oriended Programming in Sinhala
Object Oriended Programming in Sinhala Object Oriended Programming in Sinhala
Object Oriended Programming in Sinhala
 
Tips For A Better Undergraduate Research
Tips For A Better Undergraduate ResearchTips For A Better Undergraduate Research
Tips For A Better Undergraduate Research
 
Basics of Block Chain
Basics of Block ChainBasics of Block Chain
Basics of Block Chain
 
Basics of IoT
Basics of IoTBasics of IoT
Basics of IoT
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
 
Cloud Conputing Basics and some Related Research Topics
Cloud Conputing Basics and some Related Research TopicsCloud Conputing Basics and some Related Research Topics
Cloud Conputing Basics and some Related Research Topics
 
Basic Concepts and Trends in Emerging Technologies
Basic Concepts and Trends in Emerging TechnologiesBasic Concepts and Trends in Emerging Technologies
Basic Concepts and Trends in Emerging Technologies
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
Introduction to Enterprise Applications and Tools
Introduction to Enterprise Applications and ToolsIntroduction to Enterprise Applications and Tools
Introduction to Enterprise Applications and Tools
 
Introduction to Agile Software Development & Python
Introduction to Agile Software Development & PythonIntroduction to Agile Software Development & Python
Introduction to Agile Software Development & Python
 
Agile Languages for Rapid Prototyping
Agile Languages for Rapid PrototypingAgile Languages for Rapid Prototyping
Agile Languages for Rapid Prototyping
 
Things to ponder before you start building [cooperate] software
Things to ponder before you start building [cooperate] softwareThings to ponder before you start building [cooperate] software
Things to ponder before you start building [cooperate] software
 
How to make screens and the internet safe for Children
How to make screens and the internet safe for Children How to make screens and the internet safe for Children
How to make screens and the internet safe for Children
 
Different Concepts on Databases
Different Concepts on DatabasesDifferent Concepts on Databases
Different Concepts on Databases
 
A Survey Study on Higher Education Trends among Sri Lankan IT Professionals
A Survey Study on Higher Education Trends among Sri Lankan IT ProfessionalsA Survey Study on Higher Education Trends among Sri Lankan IT Professionals
A Survey Study on Higher Education Trends among Sri Lankan IT Professionals
 
A Survey Study on Higher Education Trends among Information Technology Prof...
A Survey Study  on  Higher Education Trends among Information Technology Prof...A Survey Study  on  Higher Education Trends among Information Technology Prof...
A Survey Study on Higher Education Trends among Information Technology Prof...
 
Professionalism and Industry Expectations related to IT industry
Professionalism and Industry Expectations related to IT industry  Professionalism and Industry Expectations related to IT industry
Professionalism and Industry Expectations related to IT industry
 

Recently uploaded

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 

Recently uploaded (20)

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 

Triggers and Stored Procedures

  • 1. Stored Procedure & Triggers Tharindu Weerasinghe www.tharinduweerasinghe.com
  • 2. l * A stored procedure is a segment of declarative SQL statements stored inside the database catalog. (directory of information in database). * A stored procedure can be invoked by triggers, other stored procedures, and programming languages in the likes of Java, Python, PHP. Stored Procedures
  • 4. l Advantages of Stored Procedures * Increase the performance of applications. * Reduce traffic between the application and database server. * Reusable and transparent to all applications that access the particular database. * Secure.
  • 5. l Disadvantages of Stored Procedures * If there are many procedures, the memory consumption will be high and the overall system might stuck! * Can't implement complex business logics. * Not easy to maintain. * Hard to debug the stored procedures.
  • 6. A sample – Initial Setup I aussume you all have a mysql user in your lab. mysql -u username -p If you know the root password let's login as root mysql -u root -p  CREATE DATABASE dbname; USE dbname; These things you should know by now as you should have done these in your previous course. So our dbname is dblessons;
  • 7. A sample – Initial Setup I aussume you all have a mysql user in your lab. mysql -u username -p If you know the root password let's login as root mysql -u root -p  CREATE DATABASE dbname; USE dbname; These things you should know by now as you should have done these in your previous course. So our dbname is dblessons;
  • 8. A sample – Create Tables CREATE TABLE `inventory` (   `seqid` int(20) NOT NULL  AUTO_INCREMENT,   `itemtype` varchar(300) NOT NULL,   `itemname` text NOT NULL,   `itemid` varchar(20) NOT NULL,   `usedby` int(10) DEFAULT NULL,   PRIMARY KEY (`seqid`),   UNIQUE KEY `itemid` (`itemid`) ) ENGINE=InnoDB AUTO_INCREMENT=123  DEFAULT CHARSET=latin1; /*!40101 SET character_set_client =  @saved_cs_client */; CREATE TABLE `employees` (   `empid` int(10) unsigned NOT NULL,   `name` varchar(300) NOT NULL,   `homeaddress` text NOT NULL,   `email` varchar(200) NOT NULL,   `phone` varchar(20) NOT NULL,   `salary` varchar(20) NOT NULL,   `joineddate` varchar(25) NOT NULL,   `lastincrementdate` varchar(25)  NOT NULL,   `dateofbirth` varchar(25) NOT  NULL,   `designation` varchar(30) NOT  NULL,   `leaves` int(11) DEFAULT NULL,   `resigneddate` varchar(25) DEFAULT  NULL,   `expertise` varchar(75) DEFAULT  NULL,   `nic` varchar(10) DEFAULT NULL,   PRIMARY KEY (`empid`) ) ENGINE=InnoDB DEFAULT  CHARSET=latin1;
  • 9. A sample – Insert Some Records INSERT INTO `employees` VALUES(1,'Nimal Shantha','No.1, rnGood  Road,rnNugegoda.',' ­',' ­ ','LKR 100,000.00','2014­10­03','2014­10­ 10','1981­11­23','Manager',0,'2015­03­05',NULL,NULL), (2,'Ruwan Darshana','No.1, rnFine  Road,rnNugegoda','ruwan@abc.com','777101010','200,000','2014­10­03','2016­ 01­15','1983­02­16','Head of Operations',24,'','Management, C++, Core Java,  Python, Node JS','840141615V'); INSERT INTO `inventory` VALUES (1,'Laptop','NXMLZ0F8BE3400 (Adapter­ F210821437003201)','LP001',23),(2,'Laptop','NXMCAS01010847600 (Adapter­ F5TB0429143195)','LP002',20),(4,'Laptop','D499B12 (Adapter­CN­06TM1C­72438­ 45K­2D6C­A01)','LP003',21),(9,'Laptop','NXG3HSG10E57E7600 (Adapter­ KP06503013548084D6PE03)','LP004',22),(11,'Laptop','NXMLZSG0F8DB3400  (Adapter­F210821438001685)','LP005',16),(12,'Laptop','NXM24440F8563400  (Adapter­ADT KP06503013548F883EPE03)','LP006',27);
  • 11. A sample – Call and See a Procedure (MySQL, MariaDB) Calling the created procedure: CALL item_type(“Laptop”);  <DELIMITER value declared above, which  is *> See the created procedure: SHOW CREATE PROCEDURE  item_type; <DELIMITER value  declared above, which is *>
  • 12. A sample – Complex Procedure – Try something like these! CREATE PROCEDURE   Withdraw                             /*  Routine name */   (parameter_amount DECIMAL(6,2),     /*  Parameter list */   parameter_teller_id INTEGER,   parameter_customer_id INTEGER)   MODIFIES SQL DATA                   /*  Data access clause */   BEGIN                        /* Routine  body */     UPDATE Customers         SET balance = balance ­  parameter_amount         WHERE customer_id =  parameter_customer_id;     UPDATE Tellers         SET cash_on_hand = cash_on_hand +  parameter_amount         WHERE teller_id =  parameter_teller_id;     INSERT INTO Transactions VALUES (         parameter_customer_id,         parameter_teller_id,         parameter_amount);   END;
  • 13. Database Triggers * A SQL trigger is a set of SQL statements stored in the database catalog. * A SQL trigger is run (or we say fired) whenever an associated event (with a) table occurs e.g.,  insert, update or   delete.
  • 14. l Advantages of Triggers * Can check errors in the business logic in the db layer. * Provide an alternative way to check data integrity. * Useful to audit the changes of data in tables.
  • 15. l Disdvantages of Triggers * Triggers can only provide an extended validation and they cannot do all the validations. Some basic validations have to be done in the application layer. e.g. you can validate user’s inputs in the client side by using JavaScript or on the server side using server-side scripting languages such as JSP, PHP, ASP.NET, Perl. * May increase the overhead of the db. * Triggers are invoked and executed invisible from the client applications, therefore, it is difficult to figure out what happens in the database layer.
  • 16. A sample – Trigger, related to a db log (first create 2 tables) CREATE TABLE `projects` (   `projid` varchar(20) NOT NULL,   `projname` varchar(30) NOT NULL,   `starteddate` varchar(25) NOT NULL,   `currentstatus` varchar(25) NOT NULL,   `projinfo` varchar(300) DEFAULT NULL,   PRIMARY KEY (`projid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE project_audit (     id INT AUTO_INCREMENT PRIMARY  KEY,     projid VARCHAR(50) NOT NULL,     projname VARCHAR(50) NOT NULL,     currentstatus  VARCHAR(50)NOT  NULL,     action VARCHAR(50) DEFAULT  NULL,     changedat DATETIME DEFAULT  NULL );
  • 17. A sample – Now Create the Trigger DELIMITER $$$ CREATE TRIGGER after_project_update      AFTER UPDATE ON projects     FOR EACH ROW  BEGIN     INSERT INTO project_audit     SET action = 'update',      projid = OLD.projid,      projname = OLD.projname,      changedat = NOW();  END $$$ DELIMITER; This will list down all triggers you have created: SHOW TRIGGERS; $$$ 
  • 18. A sample – Trigger, related to a db log (secondly enter some values to the projects table) LOCK TABLES `projects` WRITE; /*!40000 ALTER TABLE `projects` DISABLE KEYS */; INSERT INTO `projects` VALUES  ('Centralized','ERPCentralized','2016­11­21','In­ Progress','  Enterprise Version of ERPC'), ('ERPC','ERPC PHP','2016­10­02','In­Progress','Aimed  for Customers'),('Tree­ECOn','Tree ECOn','2015­02­ 13','On­Hold','  Tree STB ­ ECO'); /*!40000 ALTER TABLE `projects` ENABLE KEYS */; UNLOCK TABLES;
  • 19. A sample – Now Create the Trigger DELIMITER $$$ CREATE TRIGGER after_project_update      AFTER UPDATE ON projects     FOR EACH ROW  BEGIN     INSERT INTO project_audit     SET action = 'update',      projid = OLD.projid,      projname = OLD.projname,      changedat = NOW();  END $$$ DELIMITER; This will list down all triggers you have created: SHOW TRIGGERS; $$$ 
  • 20. l How to check the above Trigger? We created a trigger that will execute after an update. Hence we need to update the project table first. UPDATE projects SET projname  = "Fruit ECOn" WHERE projid =  "Tree­ECOn"; $$$ Remember our delimiter this time is, $$$ Now, if you check your project_audit table then you will see a new record being added.
  • 21. l How to check the above Trigger? (contd.)
  • 22. So what are the triggering options? BEFORE INSERT – activated before data is inserted into the table. AFTER INSERT – activated after data is inserted into the table. BEFORE UPDATE – activated before data in the table is updated. AFTER UPDATE – activated after data in the table is updated. BEFORE DELETE – activated before data is removed from the table. AFTER DELETE – activated after data is removed from the table. Do more examples guys! Play with these! Enjoy triggering!