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

  • SEARCH
  • Home
  • 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 6841113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:55:36+00:00 2026-05-26T23:55:36+00:00

I have a question about sql relation conception. I have a simple example. A

  • 0

I have a question about sql relation conception. I have a simple example.
A table person, country and I want to record the history where person had lived.

CREATE TABLE person
(
    person_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT
);

CREATE TABLE country
(
    country_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT
);

First solution :

create table person_live_country
(
    plc_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
    person_id INT UNSIGNED NOT NULL,
    country_id INT UNSIGNED NOT NULL,
    FOREIGN KEY (person_id) REFERENCES person (person_id),
    FOREIGN KEY (country_id) REFERENCES country (country_id)
);

Second solution :

create table person_live_country
(
    person_id INT UNSIGNED NOT NULL,
    country_id INT UNSIGNED NOT NULL,
    PRIMARY KEY (person_id, country_id),
    FOREIGN KEY (person_id) REFERENCES person (person_id),
    FOREIGN KEY (country_id) REFERENCES country (country_id)
);

What is the best pattern : conception, performance, convenience ? In the future I want to map the tables with JPA.

Thanks.

  • 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-05-26T23:55:36+00:00Added an answer on May 26, 2026 at 11:55 pm

    While the second solution is sufficient and slightly space efficient, I would recommend the first solution for the following reasons:

    • If you want to extend your table design in future, for example to add fromdate and todate cloumns in person_live-country table, the composit primary key in the second solution will no longer work. The same person can live in the same country more than once in his lifetime.
    • If you need to refer to person_live-country table from another table as a foreign key, the fisrt solution is easier.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about updating table through t-sql. The client may want to
I want to ask a question about the SQL. I have the following table.
I have a question about User-Defined Table Types in SQL Server 2008. For the
I have a question about TSQL function Update. For example, I have a table
I want to make one question about oracle/sql query. I have some data like
My question about My SQL is, I have a table where users enter time
I have a question about SQL Server indexes. I'm not a DBA and assume
i have a general question about how sql server evaluates the joins.The query is
I have a question about locking. This doesn't have to be only about record
I am new to php and sql, and i have one tiny question about

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.