我有以下两个MySQL表的基本论坛。第一个表格包含主题,第二个表格包含对特定主题的回复。 我想知道这个数据库设计中的外键概念。我需要在这里添加外键吗?它将如何有用,以及如何添加下列表格。谢谢。我的数据库表中是否需要外键?
--
-- 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 ;
感谢您的回复。你可以给我一个例子,我可以如何添加索引到上面的两个表? – Roman 2011-06-05 12:03:19
再次感谢您的回复。您能告诉我哪种方法更好,通过将存储引擎更改为InnoDB来添加索引或使用外键。我只关心性能等。 – Roman 2011-06-05 13:21:40
@Roman:包括一些关于何时切换到InnoDB的建议。希望对你的决定有所帮助。 – Steffen 2011-06-05 14:11:53