what is the main difference between after trigger and
instead trigger.

Answers were Sorted based on User's Feedback



what is the main difference between after trigger and instead trigger...

Answer / durga prasad

After Trigger fires an operation after any
insert,update,delete operations performed on a table.

Instead Of Trigger fires an operation instead of performing
user specified operation.

u can create instead of trigger on views but u can not
create after triggers on views

Is This Answer Correct ?    38 Yes 5 No

what is the main difference between after trigger and instead trigger...

Answer / rajneesh hajela

ALTER VIEW Employee AS
SELECT P.SSN as SSN FROM Person P, EmployeeTable E
WHERE P.SSN = E.SSN



CREATE TRIGGER IO_Trig_INS_Employee ON Employee
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON
-- Check for duplicate Person. If there is no duplicate, do
an insert.
IF (NOT EXISTS (SELECT P.SSN
FROM Person P, inserted I
WHERE P.SSN = I.SSN))
INSERT INTO Person
SELECT SSN,Name,Address,Birthdate
FROM inserted
ELSE
-- Log an attempt to insert duplicate Person row in
PersonDuplicates table.
INSERT INTO PersonDuplicates
```````````````````````````````



FROM inserted
-- Check for duplicate Employee. If no there is duplicate,
do an INSERT.
IF (NOT EXISTS (SELECT E.SSN
FROM EmployeeTable E, inserted
WHERE E.SSN = inserted.SSN))
INSERT INTO EmployeeTable
SELECT EmployeeID,SSN, Department, Salary
FROM inserted
ELSE
--If there is a duplicate, change to UPDATE so that there
will not
--be a duplicate key violation error.
UPDATE EmployeeTable
SET EmployeeID = I.EmployeeID,
Department = I.Department,
Salary = I.Salary
FROM EmployeeTable E, inserted I
WHERE E.SSN = I.SSN
END


syntex can be wrong u see only logic


Instead Of Trigger fires an operation instead of performing
user specified operation.

u can create instead of trigger on views but u can not
create after triggers on views

Rajneesh Hajela

Is This Answer Correct ?    3 Yes 7 No

Post New Answer

More SQL Server Interview Questions

What is sql injection and why is it a problem? : sql server security

0 Answers  


What is the contrast between sql and mysql?

0 Answers  


What function does a database engine serve in the sql server?

0 Answers  


Tell me what is difference between view and materialized view?

0 Answers  


What are the types of lock supported by ?

0 Answers   HCL,






What is indexed views? plz explain with example?

2 Answers  


What is difference between table aliases and column aliases? Do they affect performance?

0 Answers  


When would you use sql joins?

0 Answers  


What are the different subsets of sql?

0 Answers  


Security Question- SQL DBA exparts, need your help...

3 Answers  


What are the different Topologies in which Replication can be configured?

0 Answers  


How do I repair damaged sql server mdf file database? In previous day my mdf file has got damage due to unknown reasons then I used dbcc chekcdb command but it failed, MDF file is important for me, I don’ know that how to get back mdf file data. Please anyone suggest me?

0 Answers  


Categories