Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:08:03+00:00 2026-06-09T06:08:03+00:00

From Previous Question I got some idea about having composite primary key in n-m

  • 0

From Previous Question I got some idea about having composite primary key in n-m relationships. My condition is very similary yet a little different.

[Person]

    PERSON_ID: int, primary key
    CLIENT_ID: int, primary key
    Name: nvarchar(xx)
    primary_key( PERSON_ID, CLIENT_ID);

[Group]

    GROUP_ID: int
    CLIENT_ID: int
    Name: nvarchar(xx)
    primary_key( GROUP_ID, CLIENT_ID);

Now when I use mysql-workbench tool to generate a relationship table what it does is it creates a table:

option 1:

    [PersonHasGroup]

    PERSON_ID: int 
    CLIENT_ID: int 
    GROUP_ID: int
    CLIENT1_ID: int
primary_key( PERSON_ID, CLIENT_ID, GROUP_ID, CLIENT1_ID);

In my case both client_id would normally have the same value so I edited the table to look like

option 2:

    [PersonHasGroup]

    PERSON_ID: int
    CLIENT_ID: int
    GROUP_ID: int
primary_key( PERSON_ID, CLIENT_ID, GROUP_ID);

Are those a good practices? What my other colleagues prefer is a little different. they use:

Option 3:

   [PersonHasGroup]
    PERSON_HAS_GROUP_ID: int, auto-increment
    CLIENT_ID: int        
    PERSON_ID: int, foreign key
    GROUP_ID: int, foreign key
primary_key( PERSON_HAS_GROUP_ID, CLIENT_ID);

Which of the practise would be suitable when my relationship would be many-to-many explanation with an example would be a lot helpful 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:08:06+00:00Added an answer on June 9, 2026 at 6:08 am

    I prefer to have a single id for easy referencing, and another unique key for the unique pair, never used workbench, so here is it first in plain sql:

    CREATE TABLE person_has_group (
        person_has_group_id SERIAL,
        client_id BIGINT UNSIGNED NOT NULL REFERENCES clients (client_id),
        person_id BIGINT UNSIGNED NOT NULL,
        group_id BIGINT UNSIGNED NOT NULL,
        FOREIGN KEY (client_id, person_id) REFERENCES persons (client_id, person_id),
        FOREIGN KEY (client_id, group_id) REFERENCES groups (client_id, group_id),
        UNIQUE KEY (client_id, person_id, group_id)
    );
    

    and proberly somthing like this in “workbench”:

    [PersonHasGroup]
        PERSON_HAS_GROUP_ID: int, auto-increment
        CLIENT_ID: int        
        PERSON_ID: int, foreign key
        GROUP_ID: int, foreign key
        primary_key( PERSON_HAS_GROUP_ID)
        unique_key( CLIENT_ID, PERSON_ID, GROUP_ID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a CSS related question, I got one good answer from my previous
From my previous question about timezones , I decided to use the Ruby gem
This stems from a previous question I asked - about a write conflict with
I'm having some trouble with the idea of accessing variables from other classes. I
I got some questions about ListViews. first question : I got 5 listviews made
I asked about pipes in a previous question, got that working perfectly. However I
for Lock Screen programmatically using Android. I got some good ideas from Stackoverflow previous
Further on from my previous question about preg_split which was answers super fast, thanks
From My Previous question sending request to apple - from iphone custom application Here,
From a previous question on Stackoverflow Iterating through/Parsing JSON Object via JavaScript .... My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.