miércoles, 6 de junio de 2012

Clase Trigger


create table Autor(
idAutor int,
nombre varchar(30),
constraint Pk_idAutor primary key (idAutor)  
);

begin
insert into Autor values(7);
insert into Autor VALUES(1);
insert into Autor VALUES(2);
insert into Autor VALUES(3);
insert into Autor VALUES(4);
insert into Autor VALUES(5);
end;

create table Libro(
IdLibro integer,
IdAutor integer,
constraint Pk_idLibro primary key (IdLibro),
constraint Fk_IdAutor foreign key (IdAutor) references Autor
);

begin
insert into Libro values(1, 1);
insert into Libro values(2, 1);
insert into Libro values(3, 2);
insert into Libro values(4, 3);
end;

create sequence seqAutor
start with 1 increment by 10
nocache
nocycle;

create or replace trigger MiPrimerTrigger
after delete on Autor
for each row
begin
  DELETE FROM Libro
  WHERE IdAutor = :old.IdAutor;
end;

begin
delete from Autor
where idAutor = 1;
end;

select * from Libro;

No hay comentarios:

Publicar un comentario