mysql - Reserve/Assign a new row in another table with each row added in one -


i'll find out if it's possible following:

  • after insertion of data table a, row created automatically in table b , note_id (its primary key) stored in 1 of attributes (which foreign key references primary key in table b) in table a.

 create table table_a ( d_id int(5) not null auto_increment,  user_id int(8) not null,  note_id int(5) not null, -- foreign key points table b   primary key (d_id) ) engine=innodb default charset=latin1;   create table table_b ( note_id int(5) not null auto_increment,  note_description varchar(50) null,   primary key (note_id) ) engine=innodb default charset=latin1; 

thanks!

 delimiter $$  create trigger ins_document  after insert on table_a each row  begin    set @notenum=(select max(note_id) table_b);    if(@notenum=0) begin new.note_id=1;    end;    else      new.note_id=@notenum+1;    end if;  insert table_b (note_id) values (new.note_id);   end$$  delimiter ; 

have triggers: create trigger here can react on events inserts table , define respective actions that.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -