Skip to content

Commit 651d96c

Browse files
committed
Update important.md
1 parent 0c5dc7d commit 651d96c

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

important.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,33 +237,31 @@ DROP VIEW IF EXISTS joinedAlbum;
237237

238238
## Q. What are the triggers in SQL?
239239

240-
A trigger is a special type of stored procedure that automatically executes when a user tries to modify data through a DML event (data manipulation language). A DML event is an INSERT, UPDATE or DELETE statement on a table or view:
240+
A trigger is a stored procedure in database which automatically invokes whenever a special event in the database occurs. For example, a trigger can be invoked when a row is inserted into a specified table or when certain table columns are being updated.
241241

242-
```sql
243-
CREATE OR MODIFY TRIGGER trigger_name
244-
WHEN EVENT
245-
246-
ON table_name TRIGGER_TYPE
242+
**Syntax:**
247243

248-
EXECUTE stored_procedure
244+
```sql
245+
CREATE [OR REPLACE ] TRIGGER <trigger_name>
246+
{BEFORE | AFTER | INSTEAD OF }
247+
{INSERT [OR] | UPDATE [OR] | DELETE}
248+
ON <table_name>
249+
[FOR EACH ROW]
250+
WHEN (condition)
251+
[trigger_body]
249252
```
250253

251-
WHEN:
252-
* BEFORE – invoke before the event occurs
253-
* AFTER – invoke after the event occurs
254-
255-
EVENT:
256-
* INSERT – invoke for insert
257-
* UPDATE – invoke for update
258-
* DELETE – invoke for delete
259-
260-
TRIGGER_TYPE:
261-
* FOR EACH ROW
262-
* FOR EACH STATEMENT
254+
**Example:**
263255

264256
```sql
265-
!-- Delete a specific trigger
266-
DROP TRIGGER trigger_name
257+
CREATE TRIGGER employee_name
258+
after INSERT
259+
on
260+
employee
261+
for each row
262+
BEGIN
263+
UPDATE employee set full_name = first_name || ' ' || last_name;
264+
END;
267265
```
268266

269267
<div align="right">

0 commit comments

Comments
 (0)