WHAT IS TRIGGERS IN SQL? AND WHAT IS THE BENIFIT?
Answers were Sorted based on User's Feedback
Answer / mallika
Triggers are the system generated events.
for example,
u have a table emp,in tat u can create a trigger which will
be activated if anyone performs any action such as insert,
update, delete on tat table.In tat trigger u can write code
which copies the updated info into another table.
we can provide security to the data by mentioning before
clause in tat trigger by which we can restrict the
modifications anyone can make to our table.
CREATE TRIGGER DelhiDel ON [Customers]
FOR DELETE
AS
IF (SELECT state FROM deleted) = ‘Delhi’
BEGIN
PRINT ‘Can not remove customers from Delhi’
PRINT ‘Transaction has been canceled’
ROOLBACK
END
| Is This Answer Correct ? | 46 Yes | 5 No |
Answer / sandeep
Triggers are also a stored procedure but it has some limits
and advantages over stored procedure.
first of all its limits. It cant accept or return values by
parameters whereas stored procedures do. It is called by
database server not by application or user.
It is generally treated as a constraint. It also make sure
the integrity of the data. We cud implement business rules
successfully by using triggers without writting a single
code in application. This is the main benifit of this
object we can change the business rule very easly from
database server when the actual business rules change that
means we dont want to edit and recompile the program soruce
code.
It will make problems in import process unless we switch
off the triggers.
There are 3 types of triggers in connection with insert,
update and delete statements
1. Before trigger
2. After Trigger
3. Instead of trigger
1. Before trigger fires before the manipulation of the data
happens by insert, update and delete statements. By using
this we cud do pre proces. ie updating other tables, pre
process of data, ..etc. After this actual manipulation
happens.
2. After triggers fires after the manipulation of the data
happens by insert, update and delete statements
3. Instead-of trigger. This trigger replaces the actual
manipulation statements. That means actual manipulation
statement wont work instead of this trigger will do the
manipulation work (statements in the trigger) by accepting
values from statement.
| Is This Answer Correct ? | 22 Yes | 2 No |
A trigger is a stored procedure that goes into effect when
you insert, delete, or update data in a table. You can use
triggers to perform a number of automatic actions, such as
cascading changes through related tables, enforcing column
restrictions, comparing the results of data modifications,
and maintaining the referential integrity of data across a
database.
| Is This Answer Correct ? | 12 Yes | 5 No |
Answer / subbarayudu
A Trigger is a block of code,fired whenever data in the underlying table is affected by any of the Data Manipulation Language (DML) statements -INSERT,UPDATE,OR DELETE.
whenever trigger fires,two special tables are created-
1.insert table 2.Delete table.
1.inserted table contains copy of all records that are insetred in the trigger table.
2.deleted table contains all records that have been deleted from trigger table.this table is used to refer old values.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / sumesh
There are mainly two type trigger
1)After trigger
2)Insted of trriger
Baisicalt its like a stroeprocedure...
| Is This Answer Correct ? | 12 Yes | 11 No |
Answer / rami reddy.k
Triggers are the system generated events.
for example,
u have a table emp,in tat u can create a trigger which will
be activated if anyone performs any action such as insert,
update, delete on tat table.In tat trigger u can write code
which copies the updated info into another table.
A trigger is a stored procedure that goes into effect when
you insert, delete, or update data in a table. You can use
triggers to perform a number of automatic actions, such as
cascading changes through related tables, enforcing column
restrictions, comparing the results of data modifications,
and maintaining the referential integrity of data across a
database.
| Is This Answer Correct ? | 2 Yes | 9 No |
Answer / kavithareddy
like as storeprocedure
it is userdefind function ther is no parameters
1)After trigger:
2)Insted of trriger
| Is This Answer Correct ? | 2 Yes | 17 No |
How to create dbo table in sql server?
Is foreign key unique?
How to define and use table alias names in ms sql server?
what changed between the previous version of sql server and the current version? : Sql server database administration
How can you set the threshold at which sql server will generate keysets asynchronously?
How is foreign key related to primary key?
How many full-text indexes can a table have?
Can you tell me the difference between DELETE & TRUNCATE commands?
please tell me the query to get details of the employee having the second largest salary
What is the difference between executequery () and executeupdate ()?
How do you know which index a table is using?
Do you know what is xpath?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)