Create Trigger in oracle

Asked

Viewed 52 times

0

I have three tables: Usuario, Lembrete and Lembrete_Usuario on the Oracle. I am trying to create a Rigger that when I insert in the User table and Reminder, take the ids, User and Reminder, and put in the table User.

Tables:

create table Usuario(
  idUsuario number(5),
  nome varchar2(20) not null,
  login varchar2(20) not null,
  senha varchar2(10) not null,
  email varchar2(50) not null,
  constraint idUsuario_pk primary key(idUsuario)    
);
create table Lembrete(
  idLembrete number(5),
  titulo varchar2(255),
  hora number(5,2),
  dataLemb date,
  repetir number(5),
  descricao varchar2(50),   
  constraint idLembrete_pk primary key(idLembrete)  
);

create table Lembrete_Usuario(
  idUsuario number(5),
  idLembrete number(5),
  log_usuario date,
  constraint idUsuarioLembrete_fk foreign key(idUsuario) references Usuario(idUsuario),
  constraint idLembreteUsuario_fk foreign key(idLembrete) references Lembrete(idLembrete)
);

Can someone help me?

  • Do you really need the 3 tables? The way you described, using a trigger, i don’t see a way to do this because how will you know which user id is related to the reminder id?

  • Then this table "Lembrete_usuario" was created due to the fact of being many for many, between User and Reminder.

  • I may be wrong, but I don’t think it’s possible to do it for trigger, you will need to control by the application.

  • Okay, thanks for your attention!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.