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. :-)