Автор работы: Пользователь скрыл имя, 21 Ноября 2010 в 16:57, Не определен
Создание базы данных SQL
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tI_AGENT FOR AGENT AFTER INSERT AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* INSERT trigger on AGENT */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* SCHTAT R/10 AGENT ON CHILD INSERT RESTRICT */
select count(*)
from SCHTAT
where
/* %JoinFKPK(NEW,SCHTAT," = "," and") */
NEW.№_Sotrudnika = SCHTAT.№_Sotrudnika into numrows;
IF (
/* %NotnullFK(NEW," is not null and") */
numrows = 0
) THEN
BEGIN
EXCEPTION ERWIN_CHILD_INSERT_RESTRICT;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tU_AGENT FOR AGENT AFTER UPDATE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* UPDATE trigger on AGENT */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AGENT R/24 PRODAGI ON PARENT UPDATE RESTRICT */
IF
/* %JoinPKPK(OLD,NEW," <> "," or ") */
(OLD.№_Agenta <> NEW.№_Agenta or
OLD.№_Sotrudnika <> NEW.№_Sotrudnika) THEN
BEGIN
select count(*)
from PRODAGI
where
/* %JoinFKPK(PRODAGI,OLD," = "," and") */
PRODAGI.№_Agenta = OLD.№_Agenta and
PRODAGI.№_Sotrudnika = OLD.№_Sotrudnika into numrows;
IF (numrows > 0) THEN
BEGIN
EXCEPTION ERWIN_PARENT_UPDATE_RESTRICT;
END
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* SCHTAT R/10 AGENT ON CHILD UPDATE RESTRICT */
select count(*)
from SCHTAT
where
/* %JoinFKPK(NEW,SCHTAT," = "," and") */
NEW.№_Sotrudnika = SCHTAT.№_Sotrudnika into numrows;
IF (
/* %NotnullFK(NEW," is not null and") */
numrows = 0
) THEN
BEGIN
EXCEPTION ERWIN_CHILD_UPDATE_RESTRICT;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tD_PRODAGI FOR PRODAGI AFTER DELETE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* DELETE trigger on PRODAGI */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* PRODAGI R/29 AVTO_PRODAGI ON PARENT DELETE SET NULL */
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Sotrudnika = NULL,
AVTO_PRODAGI.№_Agenta = NULL,
AVTO_PRODAGI.№_Prodagi = NULL
where
/* %JoinFKPK(AVTO_PRODAGI,OLD," = "," and") */
AVTO_PRODAGI.№_Sotrudnika = OLD.№_Sotrudnika and
AVTO_PRODAGI.№_Agenta = OLD.№_Agenta and
AVTO_PRODAGI.№_Prodagi = OLD.№_Prodagi;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tI_PRODAGI FOR PRODAGI AFTER INSERT AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* INSERT trigger on PRODAGI */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AGENT R/24 PRODAGI ON CHILD INSERT RESTRICT */
select count(*)
from AGENT
where
/* %JoinFKPK(NEW,AGENT," = "," and") */
NEW.№_Agenta = AGENT.№_Agenta and
NEW.№_Sotrudnika = AGENT.№_Sotrudnika into numrows;
IF (
/* %NotnullFK(NEW," is not null and") */
numrows = 0
) THEN
BEGIN
EXCEPTION ERWIN_CHILD_INSERT_RESTRICT;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tU_PRODAGI FOR PRODAGI AFTER UPDATE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* UPDATE trigger on PRODAGI */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* PRODAGI R/29 AVTO_PRODAGI ON PARENT UPDATE SET NULL */
IF
/* %JoinPKPK(OLD,NEW," <> "," or " */
(OLD.№_Sotrudnika <> NEW.№_Sotrudnika or
OLD.№_Agenta <> NEW.№_Agenta or
OLD.№_Prodagi <> NEW.№_Prodagi) THEN
BEGIN
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Sotrudnika = NULL,
AVTO_PRODAGI.№_Agenta = NULL,
AVTO_PRODAGI.№_Prodagi = NULL
where
/* %JoinFKPK(AVTO_PRODAGI,OLD," = ",",") */
AVTO_PRODAGI.№_Sotrudnika = OLD.№_Sotrudnika and
AVTO_PRODAGI.№_Agenta = OLD.№_Agenta and
AVTO_PRODAGI.№_Prodagi = OLD.№_Prodagi;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AGENT R/24 PRODAGI ON CHILD UPDATE RESTRICT */
select count(*)
from AGENT
where
/* %JoinFKPK(NEW,AGENT," = "," and") */
NEW.№_Agenta = AGENT.№_Agenta and
NEW.№_Sotrudnika = AGENT.№_Sotrudnika into numrows;
IF (
/* %NotnullFK(NEW," is not null and") */
numrows = 0
) THEN
BEGIN
EXCEPTION ERWIN_CHILD_UPDATE_RESTRICT;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tD_AVTO FOR AVTO AFTER DELETE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* DELETE trigger on AVTO */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AVTO R/28 AVTO_PRODAGI ON PARENT DELETE SET NULL */
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Avto = NULL
where
/* %JoinFKPK(AVTO_PRODAGI,OLD," = "," and") */
AVTO_PRODAGI.№_Avto = OLD.№_Avto;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AVTO R/27 MEXAN_AVTO ON PARENT DELETE SET NULL */
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Avto = NULL
where
/* %JoinFKPK(MEXAN_AVTO,OLD," = "," and") */
MEXAN_AVTO.№_Avto = OLD.№_Avto;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tU_AVTO FOR AVTO AFTER UPDATE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* UPDATE trigger on AVTO */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* AVTO R/28 AVTO_PRODAGI ON PARENT UPDATE SET NULL */
IF
/* %JoinPKPK(OLD,NEW," <> "," or " */
(OLD.№_Avto <> NEW.№_Avto) THEN
BEGIN
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Avto = NULL
where
/* %JoinFKPK(AVTO_PRODAGI,OLD," = ",",") */
AVTO_PRODAGI.№_Avto = OLD.№_Avto;
END
/* AVTO R/27 MEXAN_AVTO ON PARENT UPDATE SET NULL */
IF
/* %JoinPKPK(OLD,NEW," <> "," or " */
(OLD.№_Avto <> NEW.№_Avto) THEN
BEGIN
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Avto = NULL
where
/* %JoinFKPK(MEXAN_AVTO,OLD," = ",",") */
MEXAN_AVTO.№_Avto = OLD.№_Avto;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tI_AVTO_PRODAGI FOR AVTO_PRODAGI AFTER INSERT AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* INSERT trigger on AVTO_PRODAGI */
DECLARE VARIABLE numrows INTEGER;
Информация о работе Проектирование базы данных для торговца подержанными автомобилями