Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primary key as foreign key

i have this design

table: users
-------------
PK id_users
users

table: single_users
--------------------
PK FK users_id_users
something

table: workers
---------------
PK FK single_users_users_id_users
something

there is any problem to make a PK as foreign key? like the example above?

thanks

like image 582
user773961 Avatar asked May 30 '26 23:05

user773961


1 Answers

I think that's just fine as long as you have the one to many relationship between users to workers, and users to single_users.

Note: you will have to have a multiple valued PK though. Eg

users 
1 Al
2 Eve
3 Bob

user_workers
1 something_1
1 something_2

So, you would have to have the id and something as a composite primary key. Its often easier to give the workers an id field that is a primary key.

So:

user_workers
id | user_id | something
1    1         something_1
2    1         something_2
like image 61
Nate Avatar answered Jun 01 '26 11:06

Nate