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 6918293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:50:24+00:00 2026-05-27T09:50:24+00:00

I have 2 tables : first one is something like that : Person first_name

  • 0

I have 2 tables :

first one is something like that :

Person
       first_name (primary key)
       family_name (primary key)
       age
       [other things..]

second one is :

Doctor
       first_name
       family_name
       specialty

So basically, in the table Person, their can’t be 2 Person with the same first_name and family_name. This works well if I both set them on primary key using phpmyadmin.

My problem is that now I want to make it impossible to add a Doctor who is not a Person. I’ve tried putting a foreign key constraint on doctor.first_name and doctor.family_name, but it obviously doesn’t fix my issue.

(Don’t ask me to use an id or something, my tables are much more complicated than that and I can’t use an id, it has to be a table with composite primary key).

  • 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-27T09:50:25+00:00Added an answer on May 27, 2026 at 9:50 am

    Your wording is not accurate. A table cannot have 2 Primary Keys. It can have, however, a compound (composite) Primary Key, that is made of 2 or more columns.

    CREATE TABLE Person
    (      first_name 
    ,      family_name 
    ,      age
    ,      ...
    ,   PRIMARY KEY (first_name, family_name)
    )
    

    Leaving aside discussions about surrogate vs. natural keys, when you have such a compound Primary Key, any Foreign Key from another table should be a compound one and reference your compound Primary Key:

    CREATE TABLE Doctor
    (      first_name
    ,      family_name
    ,      specialty
    ,      ...
    ,   PRIMARY KEY (first_name, family_name)
    
    ,   FOREIGN KEY (first_name, family_name)
          REFERENCES Person (first_name, family_name)
    )  
    

    This kind of foreign key constraint, where the PRIMARY KEY of a table (Doctor) is also a FOREIGN KEY to another table (Person) is the common solution for a 1::0..1 relationship (also called supertype/subtype).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, the first has a primary key that is an identity,
I have a view that is joining two tables and ordering by the first
Say if I have 2 tables. The first one holds users ids and their
I have 2 tables, one with a list of location ID's and identifiers, like
I have a stored procedure that does something like: IF @Param = '1' SELECT
Feel like this should be something easy that I'm missing. I have a table
I want to build something so that a person can have many email addresses
I have 5 tables. how to update one data that check if this data
i want to do for a table something like this. I have two tables
I have got two tables: tbl_sms tbl_bids The above two table holds something like

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.