Insert & Update Trigger

Results 1 to 2 of 2

Thread: Insert & Update Trigger

  1. #1
    Join Date
    Dec 1969

    Default Insert & Update Trigger

    I have a Table Called tblEmpl and another called tblTrackEmpl<BR><BR>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.<BR><BR>i wrote Two Trigger onr for INSERT and other for UPDATE which is as follows<BR><BR><BR>CREATE TRIGGER EMPL_INSERT ON tblEmpl AFTER INSERT<BR>AS<BR>IF @@ROWCOUNT=0 RETURN<BR>INSERT tblTrackEmpl<BR>SELECT * FROM inserted<BR><BR><BR><BR>CREATE TRIGGER EMPL_update ON tblEmpl AFTER UPDATE<BR>AS<BR> declare<BR> @id1 int<BR>begin<BR> select @id1=id from inserted<BR>IF update(emplcode)<BR>and<BR> (select count(*) from Inserted) = 1<BR><BR>INSERT tblTrackEmpl<BR>SELECT * FROM tblEmpl where id=@id1<BR>End<BR><BR><BR><BR>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<BR><BR><BR>What could be the solution<BR><BR>Thanx in Advance<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Insert & Update Trigger

    I don&#039;t understand what you are saying -- it sounds like it is doing what you asked it to.<BR><BR>The Trigger is fired on update -- it does not know or care if any actual changes occur

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts