
use control

/*
 * Whenever a row is release (deleted) from the Tieline2Reservation table,
 * insert it into the Tieline2ReservationHistory table with the current time.
 */

IF OBJECT_ID('NV_ReleaseTieline2ReservationTrigger') IS NOT NULL
  DROP TRIGGER NV_ReleaseTieline2ReservationTrigger
GO

CREATE TRIGGER NV_ReleaseTieline2ReservationTrigger
ON Tieline2Reservation

FOR DELETE
AS

INSERT INTO Tieline2ReservationHistory(
	Tieline2ReservationHistory_Tieline2,
	Tieline2ReservationHistory_ControlSystem_Name,
	Tieline2ReservationHistory_User,
	Tieline2ReservationHistory_IPAddress,
	Tieline2ReservationHistory_LTC,
	Tieline2ReservationHistory_Timestamp,
	Tieline2ReservationHistory_SourcePhysLevel,
	Tieline2ReservationHistory_SourceSignalType,
	Tieline2ReservationHistory_SourcePort,
	Tieline2ReservationHistory_DestinationPhysLevel,
	Tieline2ReservationHistory_DestinationSignalType,
	Tieline2ReservationHistory_DestinationPort,
	Tieline2ReservationHistory_DownstreamPort,
	Tieline2ReservationHistory_UpstreamPort )

SELECT
	deleted.Tieline2Reservation_Tieline2,
	deleted.Tieline2Reservation_ControlSystem_Name,
	deleted.Tieline2Reservation_User,
	deleted.Tieline2Reservation_IPAddress,
	deleted.Tieline2Reservation_LTC,
	deleted.Tieline2Reservation_Timestamp,
	deleted.Tieline2Reservation_SourcePhysLevel,
	deleted.Tieline2Reservation_SourceSignalType,
	deleted.Tieline2Reservation_SourcePort,
	deleted.Tieline2Reservation_DestinationPhysLevel,
	deleted.Tieline2Reservation_DestinationSignalType,
	deleted.Tieline2Reservation_DestinationPort,
	deleted.Tieline2Reservation_DownstreamPort,
	deleted.Tieline2Reservation_UpstreamPort 
FROM deleted;
