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)
);