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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is row_number function?

597


How to enable/disable indexes?

608


Mention the different types of triggers?

562


Is there any difference between primary key and unique with the not null condition?

537


Who developed sql server?

540






How does the report manager work in SSRS?

116


Explain indexed views?

566


How can i Relate Tables in SSIS

585


whats new about truncate in sql server 2008?

2034


What types of replication are supported in sql server?

579


What are the difference between “where” and “having” clause in sql server?

593


What is proper subset of candidate key?

568


What are recommended options to be used while using db mirroring? : sql server database administration

579


Can I use sql azure as a backup with log shipping or database mirroring?

136


Can a unique index be created on a column, which contains null?

533