I'm not sure what question you are asking. From the perspective of 3NF your relationship appears to be correct: each Salary can be a user and/or a driver, each table holding different information
However...
Business logic would indicate that there should be at least one table 'above' Salary, probably Employee which should also have this user_id as a primary key (or at least a unique constraint)
You can join user and driver directly without going through salary or employee. Inner join to get records that exist in both, left join to get all records in one and records in the other if they exist or FULL OUTER JOIN to get all records in both but on a shared row if they match. If you need data from salaries employee then probably better to start there and Left Join to each if the other tables.
Sorry I didn't read your script in full. The references logic is in the wrong table; it should be in the users_management and driver_management and they should be referencing salary.user_id
As in my comments above, business logic would indicate that salary is not the correct table to be joining to as it has its own different Primary Key (id) along with a creation timestamp, and as salary will change over time you will likely get multiple records for a user in this table. You should have a table holding the employee/user data and join to this instead
Also you have data in the salary table that maybe should be held elsewhere: bank details should be part of the employee details, not salary details (security and modelling) so salary.user_id REFERENCES user(id)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm not sure what question you are asking. From the perspective of 3NF your relationship appears to be correct: each Salary can be a user and/or a driver, each table holding different information
However...
Business logic would indicate that there should be at least one table 'above' Salary, probably Employee which should also have this user_id as a primary key (or at least a unique constraint)
You can join user and driver directly without going through salary or employee. Inner join to get records that exist in both, left join to get all records in one and records in the other if they exist or FULL OUTER JOIN to get all records in both but on a shared row if they match. If you need data from salaries employee then probably better to start there and Left Join to each if the other tables.
thanks for your idea! 😊
Sorry I didn't read your script in full. The references logic is in the wrong table; it should be in the users_management and driver_management and they should be referencing salary.user_id
As in my comments above, business logic would indicate that salary is not the correct table to be joining to as it has its own different Primary Key (id) along with a creation timestamp, and as salary will change over time you will likely get multiple records for a user in this table. You should have a table holding the employee/user data and join to this instead
Also you have data in the salary table that maybe should be held elsewhere: bank details should be part of the employee details, not salary details (security and modelling) so salary.user_id REFERENCES user(id)