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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:05:21+00:00 2026-05-22T21:05:21+00:00

I have following two mysql tables for the basic discussion forum. The first table

  • 0

I have following two mysql tables for the basic discussion forum. The first table contains the topics, while the second contains the replies to the specific topic.
I want to know about the foreign key concept in this database design. Do I need to add foreign key here? How it will be useful and how can I add in following tables. Thanks.

--
-- Table structure for table `topics`
--

CREATE TABLE IF NOT EXISTS `topics` (
  `topic_id` int(11) NOT NULL AUTO_INCREMENT,
  `topic_title` varchar(255) NOT NULL,
  `topic_content` text NOT NULL,
  `topic_author_id` int(11) NOT NULL,
  `topic_date` int(10) NOT NULL,
  PRIMARY KEY (`topic_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Table structure for table `replies`
--

CREATE TABLE IF NOT EXISTS `replies` (
  `reply_id` int(11) NOT NULL AUTO_INCREMENT,
  `reply_topic_id` int(11) NOT NULL,
  `reply_content` text NOT NULL,
  `reply_author_id` int(11) NOT NULL,
  `reply_date` int(10) NOT NULL,
  PRIMARY KEY (`reply_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  • 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-22T21:05:22+00:00Added an answer on May 22, 2026 at 9:05 pm

    In general MySQL doesn’t require you to insert foreign keys. Moreover, as long as you use the MyISAM storage engine you are not able to benefit from defining foreign keys. They accept the foreign key syntax but internally they just ignore those statements, see foreign key entry in MySQL documentation for details.

    Instead you might consider defining additional indexes for the foreign key columns what might increase your query performance. You can define an index together with your table definition

    CREATE TABLE IF NOT EXISTS `replies` (
      `reply_id` int(11) NOT NULL AUTO_INCREMENT,
      `reply_topic_id` int(11) NOT NULL,
      `reply_content` text NOT NULL,
      `reply_author_id` int(11) NOT NULL,
      `reply_date` int(10) NOT NULL,
      PRIMARY KEY (`reply_id`),
      INDEX (`reply_topic_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    

    See mysql create table syntax for details.

    As an alternative you might consider changing your storage engine to InnoDB and make use of foreign keys which will add indexes to the needed columns automatically. But you will only benefit if you really need other features beside performance optimization like foreign key constraints.

    As a rule of thumb one can stick to the suggestions given in the mysql manual. If you don’t need the additional benefits like constraints the MyISAM storage engine will deliver the better performance. So, if you don’t want the database to ensure referential integrity, instead doing this on your own within your application then MyISAM with proper indexes will be the faster and better performing solution. If you want your database to ensure referential integrity, then switch to InnoDB storage engine and define foreign keys with proper constraints.

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

Sidebar

Related Questions

I have the following two mySQL tables with the 'child' table having a DELETE
I have two mysql tables that have the following structure: Table 1: ---ID---------NAME------- ---1-----
I have the following two tables, affiliates and referrers. affiliates Table id loginid 3
using mysql and php, I have two tables, I'm french so the table names
I have created two tables ORDERS and ORDERITEMS with the following constraint: alter table
I have two tables in my MySQL database (table1 and table 2). I want
I have the two following tables table A | id | name | |
I have two tables in mysql: Results Table : 1046928 rows. Nodes Table :
I have two tables in MySQL #messages table : messageid messagetitle . . #usersmessages
I have two MySql tables like the following: Cat ------ id : INT NOT

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.