sql - What are alternatives to update/delete records with a key that references multiple tables? -


i reading on threads in so, , found out example party table below incorrect because have foreign key referencing 2 tables cannot do. thought whole idea of foreign keys make sure if update or delete in 1 table, row references foreign key gets updated or deleted. doesn't whole idea of limiting foreign key reference single table kind of kill idea? way update/delete records among tables when delete key referenced in other tables?

in mobile app right now, if "party" deleted or renamed, write query check appropriate tables , delete table, condition wherever need to. "normal" way? thought on delete cascade or on update cascade trick, if it's single referenced table, might doing query on each appropriate table.

i guess question might be, if have foreign key in multiple tables, sign of bad design? foreign key in multiple tables supposed rare occurrence?

create table party (       partyname varchar(30) not null,       pcname    varchar(30) not null,       primary key (partyname, pcname),       foreign key (partyname, pcname) references pc_basic (partyname, pcname) on delete cascade,       foreign key (partyname, pcname) references pc_stats (partyname, pcname) on delete cascade       );      create table pc_basic (       partyname varchar(30) not null,       pcname    varchar(30) not null,       init      integer not null,       ac        integer not null       primary key (partyname, pcname)     );      create table pc_stats (       str integer not null,       dex integer not null,       partyname varchar(30) not null,       pcname varchar(30) not null,       primary key (partyname, pcname)       ); 

yes, in case indicates there problem relational schema design.

all 3 of tables use same primary key. expect 1 of tables "master" or important table whatever represented combination of (partyname, pcname). other 2 tables may contain supplemental, or perhaps optional information, related master table. if so, 2 supplemental tables each have single foreign key master table only.

if doesn't describe how data these tables related in business case, please provide more details. instance, if data 3 tables required in cases, option combine 3 single table.

it not always design issue have multiple foreign keys different tables, in cases foreign keys involve different set of columns.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -