adspace
Answer Posted / Harminder Kaur
A trigger in SQL and PL/SQL is a special kind of stored procedure that automatically responds to certain events (such as insert, update, or delete) on a specific table. Triggers are used to enforce business rules, maintain data integrity, and perform auditing functions. An example of a trigger in SQL would be creating an AFTER INSERT trigger on the 'employees' table to automatically assign a unique ID to each newly inserted record:
```sql
CREATE TRIGGER auto_id_insert
AFTER INSERT ON employees
FOR EACH ROW
BEGIN
SET new.id = (SELECT MAX(id) + 1 FROM employees);
END;
```
In this example, the trigger 'auto_id_insert' is created to be activated after an insert operation on the 'employees' table. For each row inserted, the new value of 'id' will be set to the maximum 'id' from the 'employees' table plus one.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the current version of sql?
Can we use distinct and group by together?
What is the best sql course?
How do I remove duplicates in two columns?
What is the current version of postgresql?
what is sql server agent? : Sql dba
Can we rollback truncate?
Is inner join faster than left join?
how many tables will create when we create table, what are they? : Sql dba
Does group by remove duplicates?
how to start mysql server? : Sql dba
Do we need to rebuild index after truncate?
what is bcp? When does it used? : Sql dba
What is your daily office routine?
how to escape special characters in sql statements? : Sql dba