CREATE TABLE camioneros 
( 
nombre CHAR(18) NULL , 
cedula CHAR(18) NOT NULL , 
telefono CHAR(18) NULL , 
direccion CHAR(1...
ALTER TABLE camioneros 
ADD CONSTRAINT XPKcamioneros PRIMARY KEY (cedula); 
CREATE TABLE camiones 
( 
matricula CHAR(18) N...
CREATE TABLE paquete 
( 
codigo CHAR(18) NOT NULL , 
provincia CHAR(18) NULL , 
nombre CHAR(18) NULL , 
cedula CHAR(18) NU...
CREATE UNIQUE INDEX XPKprovincias ON provincias 
(codigo ASC); 
ALTER TABLE provincias 
ADD CONSTRAINT XPKprovincias PRIMA...
CREATE TRIGGER tI_camioneros BEFORE INSERT ON camioneros for each row 
-- ERwin Builtin Trigger 
-- INSERT trigger on cami...
-- ERwin Builtin Trigger 
END; 
/ 
CREATE TRIGGER tD_camioneros AFTER DELETE ON camioneros for each row 
-- ERwin Builtin ...
-- ERwin Builtin Trigger 
END; 
/ 
CREATE TRIGGER tU_camioneros AFTER UPDATE ON camioneros for each row 
-- ERwin Builtin ...
/* ERwin Builtin Trigger */ 
/* camiones camioneros on child update no action */ 
/* ERWIN_RELATION:CHECKSUM="00000000", P...
END; 
/ 
CREATE TRIGGER tD_camiones AFTER DELETE ON camiones for each row 
-- ERwin Builtin Trigger 
-- DELETE trigger on ...
/ 
CREATE TRIGGER tU_camiones AFTER UPDATE ON camiones for each row 
-- ERwin Builtin Trigger 
-- UPDATE trigger on camion...
-- ERwin Builtin Trigger 
END; 
/ 
CREATE TRIGGER tI_paquete BEFORE INSERT ON paquete for each row 
-- ERwin Builtin Trigg...
THEN 
raise_application_error( 
-20002, 
'Cannot insert paquete because provincias does not exist.' 
); 
END IF; 
/* ERwin...
-- ERwin Builtin Trigger 
END; 
/ 
CREATE TRIGGER tU_paquete AFTER UPDATE ON paquete for each row 
-- ERwin Builtin Trigge...
) 
THEN 
raise_application_error( 
-20007, 
'Cannot update paquete because provincias does not exist.' 
); 
END IF; 
/* ER...
-20007, 
'Cannot update paquete because camioneros does not exist.' 
); 
END IF; 
-- ERwin Builtin Trigger 
END; 
/ 
CREAT...
paquete.codigo = :old.codigo; 
IF (NUMROWS > 0) 
THEN 
raise_application_error( 
-20001, 
'Cannot delete provincias becaus...
/* %JoinPKPK(:%Old,:%New," <> "," OR ") */ 
:old.codigo <> :new.codigo 
THEN 
SELECT count(*) INTO NUMROWS 
FROM paquete 
...
Próxima SlideShare
Cargando en…5
×

Aviles manuel hurtado katherine

170 visualizaciones

Publicado el

Modelos Erwin

Publicado en: Educación
0 comentarios
0 recomendaciones
Estadísticas
Notas
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Sin descargas
Visualizaciones
Visualizaciones totales
170
En SlideShare
0
De insertados
0
Número de insertados
2
Acciones
Compartido
0
Descargas
1
Comentarios
0
Recomendaciones
0
Insertados 0
No insertados

No hay notas en la diapositiva.

Aviles manuel hurtado katherine

  1. 1. CREATE TABLE camioneros ( nombre CHAR(18) NULL , cedula CHAR(18) NOT NULL , telefono CHAR(18) NULL , direccion CHAR(18) NULL , salario CHAR(18) NULL , destinatario CHAR(18) NULL , matricula CHAR(18) NULL ); CREATE UNIQUE INDEX XPKcamioneros ON camioneros (cedula ASC);
  2. 2. ALTER TABLE camioneros ADD CONSTRAINT XPKcamioneros PRIMARY KEY (cedula); CREATE TABLE camiones ( matricula CHAR(18) NOT NULL , modelo CHAR(18) NULL , tipo CHAR(18) NULL , potencia CHAR(18) NULL ); CREATE UNIQUE INDEX XPKcamiones ON camiones (matricula ASC); ALTER TABLE camiones ADD CONSTRAINT XPKcamiones PRIMARY KEY (matricula);
  3. 3. CREATE TABLE paquete ( codigo CHAR(18) NOT NULL , provincia CHAR(18) NULL , nombre CHAR(18) NULL , cedula CHAR(18) NULL ); CREATE UNIQUE INDEX XPKpaquete ON paquete (codigo ASC); ALTER TABLE paquete ADD CONSTRAINT XPKpaquete PRIMARY KEY (codigo); CREATE TABLE provincias ( codigo CHAR(18) NOT NULL , nombre CHAR(18) NULL );
  4. 4. CREATE UNIQUE INDEX XPKprovincias ON provincias (codigo ASC); ALTER TABLE provincias ADD CONSTRAINT XPKprovincias PRIMARY KEY (codigo); ALTER TABLE camioneros ADD (CONSTRAINT R_4 FOREIGN KEY (matricula) REFERENCES camiones (matricula) ON DELETE SET NULL); ALTER TABLE paquete ADD (CONSTRAINT R_3 FOREIGN KEY (codigo) REFERENCES provincias (codigo)); ALTER TABLE paquete ADD (CONSTRAINT R_5 FOREIGN KEY (cedula) REFERENCES camioneros (cedula) ON DELETE SET NULL);
  5. 5. CREATE TRIGGER tI_camioneros BEFORE INSERT ON camioneros for each row -- ERwin Builtin Trigger -- INSERT trigger on camioneros DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* camiones camioneros on child insert set null */ /* ERWIN_RELATION:CHECKSUM="0000ef67", PARENT_OWNER="", PARENT_TABLE="camiones" CHILD_OWNER="", CHILD_TABLE="camioneros" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_4", FK_COLUMNS="matricula" */ UPDATE camioneros SET /* %SetFK(camioneros,NULL) */ camioneros.matricula = NULL WHERE NOT EXISTS ( SELECT * FROM camiones WHERE /* %JoinFKPK(:%New,camiones," = "," AND") */ :new.matricula = camiones.matricula ) /* %JoinPKPK(camioneros,:%New," = "," AND") */ and camioneros.cedula = :new.cedula;
  6. 6. -- ERwin Builtin Trigger END; / CREATE TRIGGER tD_camioneros AFTER DELETE ON camioneros for each row -- ERwin Builtin Trigger -- DELETE trigger on camioneros DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* camioneros paquete on parent delete set null */ /* ERWIN_RELATION:CHECKSUM="0000abe1", PARENT_OWNER="", PARENT_TABLE="camioneros" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_5", FK_COLUMNS="cedula" */ UPDATE paquete SET /* %SetFK(paquete,NULL) */ paquete.cedula = NULL WHERE /* %JoinFKPK(paquete,:%Old," = "," AND") */ paquete.cedula = :old.cedula;
  7. 7. -- ERwin Builtin Trigger END; / CREATE TRIGGER tU_camioneros AFTER UPDATE ON camioneros for each row -- ERwin Builtin Trigger -- UPDATE trigger on camioneros DECLARE NUMROWS INTEGER; BEGIN /* camioneros paquete on parent update set null */ /* ERWIN_RELATION:CHECKSUM="0001e0e9", PARENT_OWNER="", PARENT_TABLE="camioneros" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_5", FK_COLUMNS="cedula" */ IF /* %JoinPKPK(:%Old,:%New," <> "," OR ") */ :old.cedula <> :new.cedula THEN UPDATE paquete SET /* %SetFK(paquete,NULL) */ paquete.cedula = NULL WHERE /* %JoinFKPK(paquete,:%Old," = ",",") */ paquete.cedula = :old.cedula; END IF;
  8. 8. /* ERwin Builtin Trigger */ /* camiones camioneros on child update no action */ /* ERWIN_RELATION:CHECKSUM="00000000", PARENT_OWNER="", PARENT_TABLE="camiones" CHILD_OWNER="", CHILD_TABLE="camioneros" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_4", FK_COLUMNS="matricula" */ SELECT count(*) INTO NUMROWS FROM camiones WHERE /* %JoinFKPK(:%New,camiones," = "," AND") */ :new.matricula = camiones.matricula; IF ( /* %NotnullFK(:%New," IS NOT NULL AND") */ :new.matricula IS NOT NULL AND NUMROWS = 0 ) THEN raise_application_error( -20007, 'Cannot update camioneros because camiones does not exist.' ); END IF; -- ERwin Builtin Trigger
  9. 9. END; / CREATE TRIGGER tD_camiones AFTER DELETE ON camiones for each row -- ERwin Builtin Trigger -- DELETE trigger on camiones DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* camiones camioneros on parent delete set null */ /* ERWIN_RELATION:CHECKSUM="0000b734", PARENT_OWNER="", PARENT_TABLE="camiones" CHILD_OWNER="", CHILD_TABLE="camioneros" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_4", FK_COLUMNS="matricula" */ UPDATE camioneros SET /* %SetFK(camioneros,NULL) */ camioneros.matricula = NULL WHERE /* %JoinFKPK(camioneros,:%Old," = "," AND") */ camioneros.matricula = :old.matricula; -- ERwin Builtin Trigger END;
  10. 10. / CREATE TRIGGER tU_camiones AFTER UPDATE ON camiones for each row -- ERwin Builtin Trigger -- UPDATE trigger on camiones DECLARE NUMROWS INTEGER; BEGIN /* camiones camioneros on parent update set null */ /* ERWIN_RELATION:CHECKSUM="0000d8e3", PARENT_OWNER="", PARENT_TABLE="camiones" CHILD_OWNER="", CHILD_TABLE="camioneros" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_4", FK_COLUMNS="matricula" */ IF /* %JoinPKPK(:%Old,:%New," <> "," OR ") */ :old.matricula <> :new.matricula THEN UPDATE camioneros SET /* %SetFK(camioneros,NULL) */ camioneros.matricula = NULL WHERE /* %JoinFKPK(camioneros,:%Old," = ",",") */ camioneros.matricula = :old.matricula; END IF;
  11. 11. -- ERwin Builtin Trigger END; / CREATE TRIGGER tI_paquete BEFORE INSERT ON paquete for each row -- ERwin Builtin Trigger -- INSERT trigger on paquete DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* provincias paquete on child insert restrict */ /* ERWIN_RELATION:CHECKSUM="0001e783", PARENT_OWNER="", PARENT_TABLE="provincias" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_3", FK_COLUMNS="codigo" */ SELECT count(*) INTO NUMROWS FROM provincias WHERE /* %JoinFKPK(:%New,provincias," = "," AND") */ :new.codigo = provincias.codigo; IF ( /* %NotnullFK(:%New," IS NOT NULL AND") */ NUMROWS = 0 )
  12. 12. THEN raise_application_error( -20002, 'Cannot insert paquete because provincias does not exist.' ); END IF; /* ERwin Builtin Trigger */ /* camioneros paquete on child insert set null */ /* ERWIN_RELATION:CHECKSUM="00000000", PARENT_OWNER="", PARENT_TABLE="camioneros" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_5", FK_COLUMNS="cedula" */ UPDATE paquete SET /* %SetFK(paquete,NULL) */ paquete.cedula = NULL WHERE NOT EXISTS ( SELECT * FROM camioneros WHERE /* %JoinFKPK(:%New,camioneros," = "," AND") */ :new.cedula = camioneros.cedula ) /* %JoinPKPK(paquete,:%New," = "," AND") */ and paquete.codigo = :new.codigo;
  13. 13. -- ERwin Builtin Trigger END; / CREATE TRIGGER tU_paquete AFTER UPDATE ON paquete for each row -- ERwin Builtin Trigger -- UPDATE trigger on paquete DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* provincias paquete on child update restrict */ /* ERWIN_RELATION:CHECKSUM="0002069f", PARENT_OWNER="", PARENT_TABLE="provincias" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_3", FK_COLUMNS="codigo" */ SELECT count(*) INTO NUMROWS FROM provincias WHERE /* %JoinFKPK(:%New,provincias," = "," AND") */ :new.codigo = provincias.codigo; IF ( /* %NotnullFK(:%New," IS NOT NULL AND") */ NUMROWS = 0
  14. 14. ) THEN raise_application_error( -20007, 'Cannot update paquete because provincias does not exist.' ); END IF; /* ERwin Builtin Trigger */ /* camioneros paquete on child update no action */ /* ERWIN_RELATION:CHECKSUM="00000000", PARENT_OWNER="", PARENT_TABLE="camioneros" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_5", FK_COLUMNS="cedula" */ SELECT count(*) INTO NUMROWS FROM camioneros WHERE /* %JoinFKPK(:%New,camioneros," = "," AND") */ :new.cedula = camioneros.cedula; IF ( /* %NotnullFK(:%New," IS NOT NULL AND") */ :new.cedula IS NOT NULL AND NUMROWS = 0 ) THEN raise_application_error(
  15. 15. -20007, 'Cannot update paquete because camioneros does not exist.' ); END IF; -- ERwin Builtin Trigger END; / CREATE TRIGGER tD_provincias AFTER DELETE ON provincias for each row -- ERwin Builtin Trigger -- DELETE trigger on provincias DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* provincias paquete on parent delete restrict */ /* ERWIN_RELATION:CHECKSUM="0000d337", PARENT_OWNER="", PARENT_TABLE="provincias" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_3", FK_COLUMNS="codigo" */ SELECT count(*) INTO NUMROWS FROM paquete WHERE /* %JoinFKPK(paquete,:%Old," = "," AND") */
  16. 16. paquete.codigo = :old.codigo; IF (NUMROWS > 0) THEN raise_application_error( -20001, 'Cannot delete provincias because paquete exists.' ); END IF; -- ERwin Builtin Trigger END; / CREATE TRIGGER tU_provincias AFTER UPDATE ON provincias for each row -- ERwin Builtin Trigger -- UPDATE trigger on provincias DECLARE NUMROWS INTEGER; BEGIN /* ERwin Builtin Trigger */ /* provincias paquete on parent update restrict */ /* ERWIN_RELATION:CHECKSUM="0000fe23", PARENT_OWNER="", PARENT_TABLE="provincias" CHILD_OWNER="", CHILD_TABLE="paquete" P2C_VERB_PHRASE="", C2P_VERB_PHRASE="", FK_CONSTRAINT="R_3", FK_COLUMNS="codigo" */ IF
  17. 17. /* %JoinPKPK(:%Old,:%New," <> "," OR ") */ :old.codigo <> :new.codigo THEN SELECT count(*) INTO NUMROWS FROM paquete WHERE /* %JoinFKPK(paquete,:%Old," = "," AND") */ paquete.codigo = :old.codigo; IF (NUMROWS > 0) THEN raise_application_error( -20005, 'Cannot update provincias because paquete exists.' ); END IF; END IF; -- ERwin Builtin Trigger END; /

×