Should we break One to Many Relation which is unidirectional into a JoinTableFirst-time database design: am I overengineering?Database normization 2nd form: does field should depend on FK also?query left join or data insert?SQL Inner Join Two Tables supplying both sets of dataDatabase 1…n relation with several owner tablesreplacing Duplicate rows in a table and in tables having foreign key reference to the 1st tableProvide name of an attribute rather than the IDHibernate One-To-Many Mapping issue using @JoinTable
Integer addition + constant, is it a group?
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
Failed to fetch jessie backports repository
Is there a problem with hiding "forgot password" until it's needed?
Would a high gravity rocky planet be guaranteed to have an atmosphere?
Is HostGator storing my password in plaintext?
Purchasing a ticket for someone else in another country?
Pre-amplifier input protection
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Anatomically Correct Strange Women In Ponds Distributing Swords
How to run a prison with the smallest amount of guards?
How does it work when somebody invests in my business?
Is `x >> pure y` equivalent to `liftM (const y) x`
What happens if you roll doubles 3 times then land on "Go to jail?"
Is expanding the research of a group into machine learning as a PhD student risky?
Why not increase contact surface when reentering the atmosphere?
How does Loki do this?
How easy is it to start Magic from scratch?
Would this custom Sorcerer variant that can only learn any verbal-component-only spell be unbalanced?
Go Pregnant or Go Home
How did Doctor Strange see the winning outcome in Avengers: Infinity War?
Is the destination of a commercial flight important for the pilot?
What is paid subscription needed for in Mortal Kombat 11?
How long to clear the 'suck zone' of a turbofan after start is initiated?
Should we break One to Many Relation which is unidirectional into a JoinTable
First-time database design: am I overengineering?Database normization 2nd form: does field should depend on FK also?query left join or data insert?SQL Inner Join Two Tables supplying both sets of dataDatabase 1…n relation with several owner tablesreplacing Duplicate rows in a table and in tables having foreign key reference to the 1st tableProvide name of an attribute rather than the IDHibernate One-To-Many Mapping issue using @JoinTable
I am currently working on an application where I have 2 Tables. User and Team. User has UserId as PK and UserPassword.
Team table has TeamId as PK and TeamName.
Originally I had one single table where I had UserId, UserPassword and TeamId but it was pointed out to me that the current design is not normalized. Hence I had to break the table into User, Team and also a Join Table named User_Team which contains UserId as PK from User table and TeamId as PK from Team table.
Constraints
One User can be in only 1 team and 1 team can have many users.
So as per my understanding, it is a OneToMany from Team to User side.
I have made UserId and TeamId together as a composite key and also made it unique in the JoinTable(User_Team) so that 1 user cannot be in multiple teams.
My query is that is it necessary to break the table into Team table seperately. Cant I just have all 3 fields in one single table. Can someone explain me how it is not normalized. Also let me know if there is a need of JoinTable in this case.
sql database hibernate database-design database-diagram
add a comment |
I am currently working on an application where I have 2 Tables. User and Team. User has UserId as PK and UserPassword.
Team table has TeamId as PK and TeamName.
Originally I had one single table where I had UserId, UserPassword and TeamId but it was pointed out to me that the current design is not normalized. Hence I had to break the table into User, Team and also a Join Table named User_Team which contains UserId as PK from User table and TeamId as PK from Team table.
Constraints
One User can be in only 1 team and 1 team can have many users.
So as per my understanding, it is a OneToMany from Team to User side.
I have made UserId and TeamId together as a composite key and also made it unique in the JoinTable(User_Team) so that 1 user cannot be in multiple teams.
My query is that is it necessary to break the table into Team table seperately. Cant I just have all 3 fields in one single table. Can someone explain me how it is not normalized. Also let me know if there is a need of JoinTable in this case.
sql database hibernate database-design database-diagram
1
If UserId is required to be unique then it is a key and (UserId,TeamId) cannot also be a key because it is not minimal (irreducible). TeamId→TeamName would be a non-key dependency resulting in an update anomaly. That's why having all three attributes in the same table would be a bad idea.
– nvogel
Mar 8 at 11:52
Could you be more informative by what you meant by minimal(irreducible) and also give me a scenario where update anomaly will arise.
– Kshitiz Bathwal
Mar 8 at 12:23
candidate key If you have the team name in a table where TeamId and TeamName are not keys then that is redundant information that has to be maintained on multiple rows. This is a data quality issue because the dependency between TeamId and TeamName is not enforced. There is the potential that the same TeamId could have multiple different names.
– nvogel
Mar 8 at 12:37
add a comment |
I am currently working on an application where I have 2 Tables. User and Team. User has UserId as PK and UserPassword.
Team table has TeamId as PK and TeamName.
Originally I had one single table where I had UserId, UserPassword and TeamId but it was pointed out to me that the current design is not normalized. Hence I had to break the table into User, Team and also a Join Table named User_Team which contains UserId as PK from User table and TeamId as PK from Team table.
Constraints
One User can be in only 1 team and 1 team can have many users.
So as per my understanding, it is a OneToMany from Team to User side.
I have made UserId and TeamId together as a composite key and also made it unique in the JoinTable(User_Team) so that 1 user cannot be in multiple teams.
My query is that is it necessary to break the table into Team table seperately. Cant I just have all 3 fields in one single table. Can someone explain me how it is not normalized. Also let me know if there is a need of JoinTable in this case.
sql database hibernate database-design database-diagram
I am currently working on an application where I have 2 Tables. User and Team. User has UserId as PK and UserPassword.
Team table has TeamId as PK and TeamName.
Originally I had one single table where I had UserId, UserPassword and TeamId but it was pointed out to me that the current design is not normalized. Hence I had to break the table into User, Team and also a Join Table named User_Team which contains UserId as PK from User table and TeamId as PK from Team table.
Constraints
One User can be in only 1 team and 1 team can have many users.
So as per my understanding, it is a OneToMany from Team to User side.
I have made UserId and TeamId together as a composite key and also made it unique in the JoinTable(User_Team) so that 1 user cannot be in multiple teams.
My query is that is it necessary to break the table into Team table seperately. Cant I just have all 3 fields in one single table. Can someone explain me how it is not normalized. Also let me know if there is a need of JoinTable in this case.
sql database hibernate database-design database-diagram
sql database hibernate database-design database-diagram
asked Mar 8 at 11:30
Kshitiz BathwalKshitiz Bathwal
338
338
1
If UserId is required to be unique then it is a key and (UserId,TeamId) cannot also be a key because it is not minimal (irreducible). TeamId→TeamName would be a non-key dependency resulting in an update anomaly. That's why having all three attributes in the same table would be a bad idea.
– nvogel
Mar 8 at 11:52
Could you be more informative by what you meant by minimal(irreducible) and also give me a scenario where update anomaly will arise.
– Kshitiz Bathwal
Mar 8 at 12:23
candidate key If you have the team name in a table where TeamId and TeamName are not keys then that is redundant information that has to be maintained on multiple rows. This is a data quality issue because the dependency between TeamId and TeamName is not enforced. There is the potential that the same TeamId could have multiple different names.
– nvogel
Mar 8 at 12:37
add a comment |
1
If UserId is required to be unique then it is a key and (UserId,TeamId) cannot also be a key because it is not minimal (irreducible). TeamId→TeamName would be a non-key dependency resulting in an update anomaly. That's why having all three attributes in the same table would be a bad idea.
– nvogel
Mar 8 at 11:52
Could you be more informative by what you meant by minimal(irreducible) and also give me a scenario where update anomaly will arise.
– Kshitiz Bathwal
Mar 8 at 12:23
candidate key If you have the team name in a table where TeamId and TeamName are not keys then that is redundant information that has to be maintained on multiple rows. This is a data quality issue because the dependency between TeamId and TeamName is not enforced. There is the potential that the same TeamId could have multiple different names.
– nvogel
Mar 8 at 12:37
1
1
If UserId is required to be unique then it is a key and (UserId,TeamId) cannot also be a key because it is not minimal (irreducible). TeamId→TeamName would be a non-key dependency resulting in an update anomaly. That's why having all three attributes in the same table would be a bad idea.
– nvogel
Mar 8 at 11:52
If UserId is required to be unique then it is a key and (UserId,TeamId) cannot also be a key because it is not minimal (irreducible). TeamId→TeamName would be a non-key dependency resulting in an update anomaly. That's why having all three attributes in the same table would be a bad idea.
– nvogel
Mar 8 at 11:52
Could you be more informative by what you meant by minimal(irreducible) and also give me a scenario where update anomaly will arise.
– Kshitiz Bathwal
Mar 8 at 12:23
Could you be more informative by what you meant by minimal(irreducible) and also give me a scenario where update anomaly will arise.
– Kshitiz Bathwal
Mar 8 at 12:23
candidate key If you have the team name in a table where TeamId and TeamName are not keys then that is redundant information that has to be maintained on multiple rows. This is a data quality issue because the dependency between TeamId and TeamName is not enforced. There is the potential that the same TeamId could have multiple different names.
– nvogel
Mar 8 at 12:37
candidate key If you have the team name in a table where TeamId and TeamName are not keys then that is redundant information that has to be maintained on multiple rows. This is a data quality issue because the dependency between TeamId and TeamName is not enforced. There is the potential that the same TeamId could have multiple different names.
– nvogel
Mar 8 at 12:37
add a comment |
1 Answer
1
active
oldest
votes
No, you do not need a JoinTable for a OneToMany relation. Just have a teamId
field on your User table and you're good to go.
As a rule of thumb:
OneToOne: Have a single table
OneToMany: Two tables, the "many" side (User
for your case) has a foreign key
ManyToMany: Have a JoinTable
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062351%2fshould-we-break-one-to-many-relation-which-is-unidirectional-into-a-jointable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, you do not need a JoinTable for a OneToMany relation. Just have a teamId
field on your User table and you're good to go.
As a rule of thumb:
OneToOne: Have a single table
OneToMany: Two tables, the "many" side (User
for your case) has a foreign key
ManyToMany: Have a JoinTable
add a comment |
No, you do not need a JoinTable for a OneToMany relation. Just have a teamId
field on your User table and you're good to go.
As a rule of thumb:
OneToOne: Have a single table
OneToMany: Two tables, the "many" side (User
for your case) has a foreign key
ManyToMany: Have a JoinTable
add a comment |
No, you do not need a JoinTable for a OneToMany relation. Just have a teamId
field on your User table and you're good to go.
As a rule of thumb:
OneToOne: Have a single table
OneToMany: Two tables, the "many" side (User
for your case) has a foreign key
ManyToMany: Have a JoinTable
No, you do not need a JoinTable for a OneToMany relation. Just have a teamId
field on your User table and you're good to go.
As a rule of thumb:
OneToOne: Have a single table
OneToMany: Two tables, the "many" side (User
for your case) has a foreign key
ManyToMany: Have a JoinTable
answered Mar 8 at 11:35
GBrandtGBrandt
54710
54710
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062351%2fshould-we-break-one-to-many-relation-which-is-unidirectional-into-a-jointable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If UserId is required to be unique then it is a key and (UserId,TeamId) cannot also be a key because it is not minimal (irreducible). TeamId→TeamName would be a non-key dependency resulting in an update anomaly. That's why having all three attributes in the same table would be a bad idea.
– nvogel
Mar 8 at 11:52
Could you be more informative by what you meant by minimal(irreducible) and also give me a scenario where update anomaly will arise.
– Kshitiz Bathwal
Mar 8 at 12:23
candidate key If you have the team name in a table where TeamId and TeamName are not keys then that is redundant information that has to be maintained on multiple rows. This is a data quality issue because the dependency between TeamId and TeamName is not enforced. There is the potential that the same TeamId could have multiple different names.
– nvogel
Mar 8 at 12:37