sr_aneesh
January 31st, 2005, 09:41 PM
I have a Table Called tblEmpl and another called tblTrackEmpl
I want that whenever a record is inserted for any New Employee in the tblEmpl table it should be Inserted to the tblTrackEmpl table. Thereafter when ever the details (for eg:emplcode) of that particular Employee is Updated (Only when Updated) in the TblEmpl Table it should be added(a new record) to the tblTrackEmpl table.
i wrote Two Trigger onr for INSERT and other for UPDATE which is as follows
CREATE TRIGGER EMPL_INSERT ON tblEmpl AFTER INSERT
AS
IF @@ROWCOUNT=0 RETURN
INSERT tblTrackEmpl
SELECT * FROM inserted
CREATE TRIGGER EMPL_update ON tblEmpl AFTER UPDATE
AS
declare
@id1 int
begin
select @id1=id from inserted
IF update(emplcode)
and
(select count(*) from Inserted) = 1
INSERT tblTrackEmpl
SELECT * FROM tblEmpl where id=@id1
End
But when ever i Just Click Update from the FrontEnd evenif i dont make anychanges to that record a new record is inserted to the tblTrackEmpl Table
What could be the solution??
Thanx in Advance
I want that whenever a record is inserted for any New Employee in the tblEmpl table it should be Inserted to the tblTrackEmpl table. Thereafter when ever the details (for eg:emplcode) of that particular Employee is Updated (Only when Updated) in the TblEmpl Table it should be added(a new record) to the tblTrackEmpl table.
i wrote Two Trigger onr for INSERT and other for UPDATE which is as follows
CREATE TRIGGER EMPL_INSERT ON tblEmpl AFTER INSERT
AS
IF @@ROWCOUNT=0 RETURN
INSERT tblTrackEmpl
SELECT * FROM inserted
CREATE TRIGGER EMPL_update ON tblEmpl AFTER UPDATE
AS
declare
@id1 int
begin
select @id1=id from inserted
IF update(emplcode)
and
(select count(*) from Inserted) = 1
INSERT tblTrackEmpl
SELECT * FROM tblEmpl where id=@id1
End
But when ever i Just Click Update from the FrontEnd evenif i dont make anychanges to that record a new record is inserted to the tblTrackEmpl Table
What could be the solution??
Thanx in Advance