MySQL 表 PRIMARY KEY 问题? [英] MySQL table PRIMARY KEY question?
本文介绍了MySQL 表 PRIMARY KEY 问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我的主键应该像这样 PRIMARY KEY (id, category_id, posts_id)
还是像这样 PRIMARY KEY (id)
?
I' was wondering should my primary key look like this PRIMARY KEY (id, category_id, posts_id)
or look like this PRIMARY KEY (id)
?
这是我的 MySQL 表.
Here is my MySQL table.
CREATE TABLE posts_categories (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
category_id INT UNSIGNED NOT NULL,
posts_id INT UNSIGNED NOT NULL,
date_created DATETIME NOT NULL,
PRIMARY KEY (id, category_id, posts_id),
UNIQUE KEY (category_id, posts_id)
);
推荐答案
The multiple column key is called a Composite Key or a Compound Key
如前所述,它们是完全有效的并且有好处.见链接.:-)
As stated they are completely valid and have benefits. See links. :-)
这篇关于MySQL 表 PRIMARY KEY 问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文