mysql - tables related with foreign key are synched with each other -


i using phpmyadmin mysql. have 4 tables project1, project2, project3 , combine table. suppose combine table connected other tables foreign keys , add data of background script project1, prject2, , project3 tables. there way update corresponding foreign keys in combine table automatically ( without manually updating record). using yii framework gui. please suggest way new mysql , yii framework.

http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

not understanding question think referring on delete , on update.

on delete & on update options

cascade set null no action restrict 

on delete & on cascade placed constraints in fk table , occur when parent id either deleted or updated.

so if change id within projects table , wish change reflected in combine table, use on update cascade.

as side note, why have 4 tables? can see need 2 tables.

please note sql below may not syntactically correct.

create table tbl_projects (   id integer not null primary key auto increment,   name varchar(255),   ...   ... ); 

method 1 creating row each project in combine table:

create table tbl_combine (   id integer not null primary key auto increment,   project_id integer,   ...   constraint `fk_combine_project`        foreign key (`project_id`)        references `tbl_project` (`id`)       on delete cascade on update cascade ); 

method 2:

create table tbl_combine (   id integer not null primary key auto increment,   project1_id integer,   project2_id integer,   project3_id integer,   ...   constraint `fk_combine_project1`        foreign key (`project1_id`)        references `tbl_project` (`id`)       on delete cascade on update cascade    constraint `fk_combine_project2`        foreign key (`project2_id`)        references `tbl_project` (`id`)       on delete cascade on update cascade    constraint `fk_combine_project3`        foreign key (`project3_id`)        references `tbl_project` (`id`)       on delete cascade on update cascade ); 

you can via gui in phpmyadmin setting foreign keys index clicking button, going table relation view , choosing options.

hope helps - have attached phpmyadmin image see.

php admin foreign key constraints


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -