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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:29:08+00:00 2026-06-12T03:29:08+00:00

I need help with a database table called Question. I want to know which

  • 0

I need help with a database table called “Question”. I want to know which layout is better out of the two below when it comes to primary keys:

Question Table method 1:

QuestionId (int 3) PK
SessionId (varchar10) PK
QuestionContent (varchar800)
NoofAnswers (int 3)
AnswerId (int 5) Auto Increment
Marks (int 3)

In the above table, QuestionId and SessionId are PK (primary Key), AnswerId is not PK, but it is auto increment.

Question Table method 2:

QuestionId (int 3)
SessionId (varchar10)
QuestionContent (varchar800)
NoofAnswers (int 3)
AnswerId (int 5) Auto Increment PK
Marks (int 3)

In the table above, only AnswerId is PK and autoincrement. But if if I do that, it means other tables which contains QuestionId will have to link to this table’s QuestionId as non keys or something like that.

The database is not letting me do PK for QuestionId, SessionId and AnswerId as its saying that AnswerId is auto increment so no need for any other primary keys.

  • 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-12T03:29:09+00:00Added an answer on June 12, 2026 at 3:29 am

    I think both cases are not good! You are giving PK’s a meaning, but PK’s should have no meaning.

    Just make your PK a int(11) Auto Increment and link tables together with a foreign key.

    Update

    Each table has its own PK. The Questions table has a QuestionId PK.

    Tying table together is based on the relation that tables have. There are different scenarios for 1:1 relations, 1:many relations and many:many relations.

    Example:

    CREATE TABLE `Questions` (
      `QuestionId` int(11) NOT NULL AUTO_INCREMENT,
      `AnswerId` int(11) DEFAULT NULL,
      PRIMARY KEY (`QuestionId`),
      KEY `FK_Answer` (`AnswerId`),
      CONSTRAINT `FK_Answer` FOREIGN KEY (`AnswerId`) REFERENCES `Answers` (`AnswersId`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    CREATE TABLE `Answers` (
      `AnswerId` int(11) NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`AnswerId`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    

    Looking from the Questions there can only be 1 answer on a question (1:1). Looking from a answer, it can be used for many questions (1:n). For a many:many relations you need a extra table.

    Here is a youtube doing some extra explanation: http://www.youtube.com/watch?v=RXOj0D80kRg

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

Sidebar

Related Questions

need help in error in database pivot. i have table tamed table_score like below:
I need help to model a table structure for my database. I have two
I have a database table that contain two fields Categories and Tags i need
I need help on the best way to design a database/tables for the following
I need your help with display of some comma separated enteries from my database.
I need some help a query. For each movie in my database that has
I know its a common question asked several times on SO. But help me
I Have a form to add a product into a database table called 'Products'
I have a SQL Server 2008 database. This database has a Table called Book.
Hi i need help with a query I have a table Where Jobs and

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.