You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: important.md
+19-21Lines changed: 19 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -237,33 +237,31 @@ DROP VIEW IF EXISTS joinedAlbum;
237
237
238
238
## Q. What are the triggers in SQL?
239
239
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.
241
241
242
-
```sql
243
-
CREATE OR MODIFY TRIGGER trigger_name
244
-
WHEN EVENT
245
-
246
-
ON table_name TRIGGER_TYPE
242
+
**Syntax:**
247
243
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]
249
252
```
250
253
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:**
263
255
264
256
```sql
265
-
!-- Delete a specific trigger
266
-
DROPTRIGGER trigger_name
257
+
CREATETRIGGERemployee_name
258
+
after INSERT
259
+
on
260
+
employee
261
+
for each row
262
+
BEGIN
263
+
UPDATE employee set full_name = first_name ||''|| last_name;
0 commit comments