nowandever29
MIS
I have a simple trigger that moves records from the main table to a history table, then move records from the load table into the main table.
This trigger is an INSERT trigger on the load table.
For some reason it's not running??? I t never fires, even when I insert records.
Thanks!
CREATE TRIGGER InsPatchStatus ON TblPatchStatusLoad
FOR INSERT AS
BEGIN
-- This trigger moves new records from the load table to the main
-- table, but first it moves any preexisting records for this server
-- to the history table from the main table, so we will always have
-- one set of records in the main table.
DECLARE @Server varchar(100)
SET @Server = (SELECT TOP 1 Computer FROM INSERTED)
INSERT INTO tbltest VALUES (@Server)
-- Copy old records for this server from the main table to the history table
INSERT INTO TblPatchStatusHist SELECT * FROM tblPatchStatus WHERE Computer = @Server
-- Remove the old records for this server from the main table
DELETE FROM TblPatchStatus WHERE Computer = @Server
-- Copy the new records for this server from the load table to the main table.
INSERT INTO TblPatchStatus SELECT * FROM tblPatchStatusLoad WHERE Computer = @Server
-- Remove the new records for this server from the load tbale.
DELETE FROM TblPatchStatusLoad WHERE Computer = @Server
END
This trigger is an INSERT trigger on the load table.
For some reason it's not running??? I t never fires, even when I insert records.
Thanks!
CREATE TRIGGER InsPatchStatus ON TblPatchStatusLoad
FOR INSERT AS
BEGIN
-- This trigger moves new records from the load table to the main
-- table, but first it moves any preexisting records for this server
-- to the history table from the main table, so we will always have
-- one set of records in the main table.
DECLARE @Server varchar(100)
SET @Server = (SELECT TOP 1 Computer FROM INSERTED)
INSERT INTO tbltest VALUES (@Server)
-- Copy old records for this server from the main table to the history table
INSERT INTO TblPatchStatusHist SELECT * FROM tblPatchStatus WHERE Computer = @Server
-- Remove the old records for this server from the main table
DELETE FROM TblPatchStatus WHERE Computer = @Server
-- Copy the new records for this server from the load table to the main table.
INSERT INTO TblPatchStatus SELECT * FROM tblPatchStatusLoad WHERE Computer = @Server
-- Remove the new records for this server from the load tbale.
DELETE FROM TblPatchStatusLoad WHERE Computer = @Server
END