sql - Adding constraint to several tables -
if have following tables:
user(user_id, name) job(job_id,...) authorised(job_id,user_id) //a job authorised done 1 or more users work(user_id, job_id) //user working on job
the question is: work
table want have constraint saying entries, user should authorised work on job. possible (as needs @ authroised
table well?
you can foreign key relationship.
create unique index unq_authorised_job_user on authorized(job_id, user_id);
(this needed if combination not primary key or unique.).
alter table work add constraint foreign key (job_id, user_id) references authorised(job_id, user_id)
Comments
Post a Comment