Oracle - creacion de tablas2

 
Vista:

creacion de tablas2

Publicado por ainhoa (10 intervenciones) el 31/01/2006 19:55:14
cuando se crean tablas en oracle ya sea oracle 8i o 9i o cualquiera de sus versiones cuando es necesario poner on delete cascade.

gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:creacion de tablas2

Publicado por JSL (186 intervenciones) el 31/01/2006 20:51:41
Usando CONSTRAINTS:

ON DELETE CASCADE

allows deletion of referenced key values in the parent table that have dependent rows in the child table and causes Oracle to automatically delete dependent rows from the child table to maintain referential integrity.

Maintaining Referential Integrity with ON DELETE CASCADE

If you use the ON DELETE CASCADE option, Oracle permits deletions of referenced key values in the parent table and automatically deletes dependent rows in the child table to maintain referential integrity.
Example

This example creates the EMP table, defines and enables the referential integrity constraint FK_DEPTNO, and uses the ON DELETE CASCADE option:



CREATE TABLE emp
(empno NUMBER(4),
ename VARCHAR2(10),
job VARCHAR2(9),
mgr NUMBER(4),
hiredate DATE,
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(2) CONSTRAINT fk_deptno
REFERENCES dept(deptno)
ON DELETE CASCADE );

Because of the ON DELETE CASCADE option, Oracle cascades any deletion of a DEPTNO value in the DEPT table to the DEPTNO values of its dependent rows of the EMP table. For example, if Department 20 is deleted from the DEPT table, Oracle deletes the department's employees from the EMP table.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:creacion de tablas2

Publicado por Maholi (1 intervención) el 07/02/2006 18:15:17
Si tienes claves foraneas, debes colocar (on delete cascade) al final de la declaracion,ya que de este modo cuando borres algun dato en una de las tablas tambien se va a borrar en las otras. ejemplo

alter table ACCESO_APLICACION_USUARIO
add constraint FK_ACCESO_A_REFERENCE_APLICAC3 foreign key (ID_APLICACION)
references APLICACION (ID_APLICACION) on delete cascade;
espero haberte ayudado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar