Автор работы: Пользователь скрыл имя, 21 Ноября 2010 в 16:57, Не определен
Создание базы данных SQL
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* PRODAGI R/29 AVTO_PRODAGI ON CHILD INSERT SET NULL */
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Sotrudnika = NULL,
AVTO_PRODAGI.№_Agenta = NULL,
AVTO_PRODAGI.№_Prodagi = NULL
where
not exists (
select * from PRODAGI
where
/* %JoinFKPK(NEW,PRODAGI," = "," and") */
NEW.№_Sotrudnika = PRODAGI.№_Sotrudnika and
NEW.№_Agenta = PRODAGI.№_Agenta and
NEW.№_Prodagi = PRODAGI.№_Prodagi
) and
/* %JoinPKPK(AVTO_PRODAGI,NEW," = "," and") */
;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AVTO R/28 AVTO_PRODAGI ON CHILD INSERT SET NULL */
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Avto = NULL
where
not exists (
select * from AVTO
where
/* %JoinFKPK(NEW,AVTO," = "," and") */
NEW.№_Avto = AVTO.№_Avto
) and
/* %JoinPKPK(AVTO_PRODAGI,NEW," = "," and") */
;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tU_AVTO_PRODAGI FOR AVTO_PRODAGI AFTER UPDATE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* UPDATE trigger on AVTO_PRODAGI */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* PRODAGI R/29 AVTO_PRODAGI ON CHILD UPDATE SET NULL */
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Sotrudnika = NULL,
AVTO_PRODAGI.№_Agenta = NULL,
AVTO_PRODAGI.№_Prodagi = NULL
where
not exists (
select * from PRODAGI
where
/* %JoinFKPK(NEW,PRODAGI," = "," and") */
NEW.№_Sotrudnika = PRODAGI.№_Sotrudnika and
NEW.№_Agenta = PRODAGI.№_Agenta and
NEW.№_Prodagi = PRODAGI.№_Prodagi
) and
/* %JoinPKPK(AVTO_PRODAGI,NEW," = "," and") */
;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AVTO R/28 AVTO_PRODAGI ON CHILD UPDATE SET NULL */
update AVTO_PRODAGI
set
/* %SetFK(AVTO_PRODAGI,NULL) */
AVTO_PRODAGI.№_Avto = NULL
where
not exists (
select * from AVTO
where
/* %JoinFKPK(NEW,AVTO," = "," and") */
NEW.№_Avto = AVTO.№_Avto
) and
/* %JoinPKPK(AVTO_PRODAGI,NEW," = "," and") */
;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tD_MEXAN FOR MEXAN AFTER DELETE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* DELETE trigger on MEXAN */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* MEXAN R/26 MEXAN_AVTO ON PARENT DELETE SET NULL */
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Mexanika = NULL,
MEXAN_AVTO.№_Sotrudnika = NULL
where
/* %JoinFKPK(MEXAN_AVTO,OLD," = "," and") */
MEXAN_AVTO.№_Mexanika = OLD.№_Mexanika and
MEXAN_AVTO.№_Sotrudnika = OLD.№_Sotrudnika;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tI_MEXAN FOR MEXAN AFTER INSERT AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* INSERT trigger on MEXAN */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* SCHTAT R/2 MEXAN 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_MEXAN FOR MEXAN AFTER UPDATE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* UPDATE trigger on MEXAN */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* MEXAN R/26 MEXAN_AVTO ON PARENT UPDATE SET NULL */
IF
/* %JoinPKPK(OLD,NEW," <> "," or " */
(OLD.№_Mexanika <> NEW.№_Mexanika or
OLD.№_Sotrudnika <> NEW.№_Sotrudnika) THEN
BEGIN
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Mexanika = NULL,
MEXAN_AVTO.№_Sotrudnika = NULL
where
/* %JoinFKPK(MEXAN_AVTO,OLD," = ",",") */
MEXAN_AVTO.№_Mexanika = OLD.№_Mexanika and
MEXAN_AVTO.№_Sotrudnika = OLD.№_Sotrudnika;
END
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* SCHTAT R/2 MEXAN 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 tI_MEXAN_AVTO FOR MEXAN_AVTO AFTER INSERT AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* INSERT trigger on MEXAN_AVTO */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AVTO R/27 MEXAN_AVTO ON CHILD INSERT SET NULL */
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Avto = NULL
where
not exists (
select * from AVTO
where
/* %JoinFKPK(NEW,AVTO," = "," and") */
NEW.№_Avto = AVTO.№_Avto
) and
/* %JoinPKPK(MEXAN_AVTO,NEW," = "," and") */
;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* MEXAN R/26 MEXAN_AVTO ON CHILD INSERT SET NULL */
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Mexanika = NULL,
MEXAN_AVTO.№_Sotrudnika = NULL
where
not exists (
select * from MEXAN
where
/* %JoinFKPK(NEW,MEXAN," = "," and") */
NEW.№_Mexanika = MEXAN.№_Mexanika and
NEW.№_Sotrudnika = MEXAN.№_Sotrudnika
) and
/* %JoinPKPK(MEXAN_AVTO,NEW," = "," and") */
;
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
END
!!
CREATE TRIGGER tU_MEXAN_AVTO FOR MEXAN_AVTO AFTER UPDATE AS
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* UPDATE trigger on MEXAN_AVTO */
DECLARE VARIABLE numrows INTEGER;
BEGIN
/* ERwin Builtin Fri Dec 11 20:50:53 2009 */
/* AVTO R/27 MEXAN_AVTO ON CHILD UPDATE SET NULL */
update MEXAN_AVTO
set
/* %SetFK(MEXAN_AVTO,NULL) */
MEXAN_AVTO.№_Avto = NULL
where
not exists (
Информация о работе Проектирование базы данных для торговца подержанными автомобилями