You are on page 1of 17

DBMS

Presentation
Topic: Trigger & Functions in DBMS
Presented to, Md Kawsar Ahmed
(Lecturer)
Dept. of CSE
R.P. Shaha University
Introduction

Arpita Das Md. Tyibor Rahman


Id: 22100026 Id: 22100080
Batch: 24th Batch: 24th
Table of contents

Introductio Trigger
01 02 1. What is trigger?

n 2.
3.
Types of trigger
Examples

Conclusion
Functions
03 1.
2.
What is Functions
Types of Functions
04 s 1. Any Question
2. Thank you
3. Examples
Trigger
What is Trigger in DBMS ?

> A Trigger in SQL is a set of statements which are executed


automatically when there is any response to certain events on
the particular table in the database.

Triggers are used to protect the data integrity in the


database.
Types of Trigger
Triggers are mainly of three types.

DML Trigger: Triggers are automatically fired when an INSERT,


UPDATE or DELETE event occurs on a table.

DDL Trigger: Triggers are automatically fired when a CREATE,


ALTER, or DROP event occurs in a database.

Logon Trigger: Triggers is fired when a LOGON event is raised


when a user session is established.
Syntax Trigger Syntax SQL
Quer
y

...
CREATE TRIGGER [Schema_name] Trigger_name DML
ON { table_name } Trigg
er
(AFTER|BEFOR) { [INSERT] [,] [UPDATE] [,]
[DELETE] }
[NOT FOR REPLICATION]
AS { SQL_statement }
Example
There, we have two tables. Let’s use triggers
in them.
Trigg
er Table
s

...
Example
Appl
y In
Trigg sert
er

...

In SQL server Trigger is more


complex then MYSQL
Example
Lets Insert Some data

In p u t
Outp
ut

...
Output For Both Table
Functions
What is Functions ?

> Functions in SQL are the database objects that contains a set
of SQL statements to perform a specific task. function
accepts input parameters, perform actions, and then return the
result

There are two type of Function


1. System Function
2. User-Defined Functions
System Functions
DDL Database Definition Functions EX: (Create ,Drop, Alter)
DML Database Manipulation Functions EX: (Insert, Delete, update,...)
DCL Database Control Functions EX: (Grant, Revoke)
TCF Transaction Control Functions EX: (commit , Rollback)
DIF Data integrity Functions EX: (Primary key, Foreign Key, Check)
AF Aggregate Functions EX: (Sum , AVG, Count , MAX, MIN)
SF String Functions EX: ( Concat , UPPER /LOWRE,LEN)
MF Math Functions EX: (ABS,ROUND,SQRT)
User-Defined Function
User-Defined Functioned are Two Types

Scalar Function Table-Valued Function

Scalar function in SQL Server Table-valued functions in SQL Server are


always accepts parameters, either the user-defined function that returns data of
single or multiple and returns a a table type. Since this function's return type
single value is a table,
Syntax
Scalar User-defined Function

CREATE FUNCTION schema_name.function_name (parameter_list)

RETURNS data_type AS
BEGIN
statements
RETURN value
END
Example
Scalar User-defined Function
Example
Using my function in my table

Output
Thank You
Any Question?
Reference
1. SQL Server Functions – javatpoint
s: 2. Chat-gpt : ChatGPT (openai.com)
3. Bard (google.com)
4. SQL Tutorial (w3schools.com)
5. Anaheim Font - 1001 Free Fonts
6. Triggers in DBMS: What They Are and How to Use Them (geopits.com)

You might also like