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













1















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.










share|improve this question

















  • 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















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.










share|improve this question

















  • 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








1








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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













  • 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













1 Answer
1






active

oldest

votes


















2














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





share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    2














    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





    share|improve this answer



























      2














      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





      share|improve this answer

























        2












        2








        2







        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 11:35









        GBrandtGBrandt

        54710




        54710





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived