sql - two foreign keys to the same numeric data type and reference it to two tables -


it´s possible create 2 foreign keys same type of numerical data in table , reference 2 tables , have exemples in down

create table admin , primary key

/* table admin*/ create table admin (id_admin number(10) not null,                      email_admin varchar(30) not null,                      password_admin varchar(10) not null); /* primary key */ alter table admin add constraint admin_pk primary key (id_admin); 

create table user , primary key

/* table user*/ create table user (id_user number(10) not null,                     email_user varchar(30) not null,                     password_user varchar(10) not null); /* primary key */ alter table user add constraint user_pk primary key (id_user); 

create table login , primary key , foreign key

/* table login*/ create table login(id_login number(10) not null,                     id_admin_user_login number(10) not null,                     email_login varchar(20) not null,                     password_login varchar(10) not null); /* primary key */ alter table login add constraint login_pk primary key (id_login);  /* foreign key reference admin*/ alter table login add constraint login_fk_admin foreign key (id_admin_user_login)  reference admin(id_admin);   /* foreign key reference user*/ alter table login add constraint login_fk_user foreign key (id_admin_user_login)  reference user(id_user); 

is possible?

having fk 2 tables in case defeats purpose - person must user , admin @ same time. admin or user in fact roles, can have, instance (oversimplified example, illustrate approach. can find more searching party-role-relationship model) ,

party (party_id (pk), name, ... .); party_login(party_login_id(pk), party_id (fk party), ...); party_role(party_id (pk,fk), role_id(pk,fk)) ;  

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -