- 13


(

Name

);

ALTER TABLE Usls

ADD CONSTRAINT XPKUsls PRIMARY KEY (Code);

CREATE TRIGGER Usls_BUH FOR Usls

BEFORE UPDATE POSITION 0

AS

BEGIN

/* BegDate */

IF (new.BegDate <> old.BegDate) THEN

BEGIN

IF (new.BegDate < old.BegDate) THEN

BEGIN

/* BegDate */

UPDATE Usls

SET EndDate = new.BegDate

WHERE ((new.BegDate BETWEEN BegDate AND EndDate) AND (PKey = new.PKey));

END

ELSE

BEGIN

/* BegDate */

UPDATE Usls

SET EndDate = new.BegDate

WHERE ((EndDate = old.BegDate) AND (PKey = new.PKey));

END

END

/* EndDate */

IF (new.EndDate <> old.EndDate) THEN

BEGIN

IF (new.EndDate > old.EndDate) THEN

BEGIN

/* EndDate */

UPDATE Usls

SET BegDate = new.EndDate

WHERE ((new.EndDate BETWEEN BegDate AND EndDate) AND (PKey = new.PKey));

END

ELSE

BEGIN

/* EndDate */

UPDATE Usls

SET BegDate = new.EndDate

WHERE ((BegDate = old.EndDate) AND (PKey = new.PKey));

END

END

/* ࠠ */

DELETE FROM Usls

WHERE ((BegDate >= new.BegDate) AND (EndDate <= new.EndDate) AND (PKey = new.PKey) AND (Code <> new.Code));

END ^

CREATE TRIGGER Usls_BIH FOR Usls

BEFORE INSERT POSITION 0

AS

BEGIN

DELETE FROM Usls

WHERE ((BegDate >= new.BegDate) AND (EndDate <= new.EndDate) AND (PKey = new.PKey));

UPDATE Usls

SET BegDate = new.EndDate

WHERE ((new.EndDate BETWEEN BegDate AND EndDate) AND (PKey = new.PKey));

UPDATE Usls

SET EndDate = new.BegDate