Организация удаленного доступа к распределенным базам данных
Рефераты >> Программирование и компьютеры >> Организация удаленного доступа к распределенным базам данных

/* Расширение EndDate */

UPDATE UslCat

SET BegDate = new.EndDate

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

END

ELSE

BEGIN

/* Сужение EndDate */

UPDATE UslCat

SET BegDate = new.EndDate

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

END

END

/* Сборка мусора */

DELETE FROM UslCat

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

END ^

CREATE TRIGGER UslCat_BIH FOR UslCat

BEFORE INSERT POSITION 0

AS

BEGIN

DELETE FROM UslCat

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

UPDATE UslCat

SET BegDate = new.EndDate

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

UPDATE UslCat

SET EndDate = new.BegDate

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

END ^

CREATE TRIGGER UslCat_BDH FOR UslCat

BEFORE DELETE POSITION 0

AS

BEGIN

UPDATE UslCat

SET EndDate = old.EndDate

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

END ^

CREATE TABLE UslCatKeys (

Code INTEGER NOT NULL

);

ALTER TABLE UslCatKeys

ADD CONSTRAINT XPKUslCatKeys PRIMARY KEY (Code);

CREATE TABLE UslDivisions (

Code INTEGER NOT NULL,

Name DESCR_TYPE,

PKey INTEGER NOT NULL,

Parent INTEGER NOT NULL,

BegDate DATE_TYPE,

EndDate DATE_TYPE

);

CREATE INDEX XIEUslDivisionsname ON UslDivisions

(

Name

);

CREATE INDEX XIEUslDivisionsParent ON UslDivisions

(

Parent

);

ALTER TABLE UslDivisions

ADD CONSTRAINT XPKUslDivisions PRIMARY KEY (Code);

CREATE TRIGGER UslDivisions_BUH FOR UslDivisions

BEFORE UPDATE POSITION 0

AS

BEGIN

/* Изменение BegDate */

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

BEGIN

IF (new.BegDate < old.BegDate) THEN

BEGIN

/* Расширение BegDate */

UPDATE UslDivisions

SET EndDate = new.BegDate

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

END

ELSE

BEGIN

/* Сужение BegDate */

UPDATE UslDivisions

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 UslDivisions

SET BegDate = new.EndDate

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

END

ELSE

BEGIN

/* Сужение EndDate */

UPDATE UslDivisions

SET BegDate = new.EndDate

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

END

END

/* Сборка мусора */

DELETE FROM UslDivisions

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

END ^

CREATE TRIGGER UslDivisions_BIH FOR UslDivisions

BEFORE INSERT POSITION 0

AS

BEGIN

DELETE FROM UslDivisions

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

UPDATE UslDivisions

SET BegDate = new.EndDate

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

UPDATE UslDivisions

SET EndDate = new.BegDate

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

END ^

CREATE TRIGGER UslDivisions_BDH FOR UslDivisions

BEFORE DELETE POSITION 0

AS

BEGIN

UPDATE UslDivisions

SET EndDate = old.EndDate

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

END ^

CREATE TABLE UslDivisionsKeys (

Code INTEGER NOT NULL

);

ALTER TABLE UslDivisionsKeys

ADD CONSTRAINT XPKUslDivisionsKeys PRIMARY KEY (Code);

CREATE TABLE UslLgots (

Code INTEGER NOT NULL,

Category INTEGER NOT NULL,

Property INTEGER,

Tax CURR_TYPE,

Usl INTEGER NOT NULL,

NachCoeff INTEGER NOT NULL,

Nalog INTEGER NOT NULL,

BegDate INTEGER NOT NULL,

Info INTEGER NOT NULL,

EndDate INTEGER NOT NULL

);

ALTER TABLE UslLgots

ADD CONSTRAINT XPKUslLgots PRIMARY KEY (Code);

CREATE TABLE UslProps (

Code INTEGER NOT NULL,

PKey INTEGER NOT NULL,

Tag INTEGER NOT NULL,

ValInteger INTEGER,

ValFloat FLOAT,

BegDate DATE_TYPE,

EndDate DATE_TYPE

);

ALTER TABLE UslProps

ADD CONSTRAINT XPKUslProps PRIMARY KEY (Code);

CREATE TRIGGER UslProps_BUH FOR UslProps

BEFORE UPDATE POSITION 0

AS

BEGIN

/* Изменение BegDate */

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

BEGIN

IF (new.BegDate < old.BegDate) THEN

BEGIN

/* Расширение BegDate */

UPDATE UslProps

SET EndDate = new.BegDate

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

END

ELSE

BEGIN

/* Сужение BegDate */

UPDATE UslProps

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 UslProps

SET BegDate = new.EndDate

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

END

ELSE

BEGIN

/* Сужение EndDate */

UPDATE UslProps

SET BegDate = new.EndDate

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

END

END

/* Сборка мусора */

DELETE FROM UslProps

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

END ^

CREATE TRIGGER UslProps_BIH FOR UslProps

BEFORE INSERT POSITION 0

AS

BEGIN

DELETE FROM UslProps

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

UPDATE UslProps

SET BegDate = new.EndDate

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

UPDATE UslProps

SET EndDate = new.BegDate

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

END ^

CREATE TRIGGER UslProps_BDH FOR UslProps

BEFORE DELETE POSITION 0

AS

BEGIN

UPDATE UslProps

SET EndDate = old.EndDate

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

END ^

CREATE TABLE UslPropsKeys (

Code INTEGER NOT NULL

);

ALTER TABLE UslPropsKeys

ADD CONSTRAINT XPKUslPropsKeys PRIMARY KEY (Code);

CREATE TABLE Usls (

Code INTEGER NOT NULL,

PKey INTEGER NOT NULL,

Division INTEGER NOT NULL,

UslType INTEGER NOT NULL,

Name CHAR(64) NOT NULL,

BegDate DATE_TYPE,

EndDate DATE_TYPE

);

CREATE INDEX XIEUslsName ON Usls


Страница: