gpt4 book ai didi

php - 如何使 key 对成为主要 key 对?

转载 作者:可可西里 更新时间:2023-11-01 07:50:07 25 4
gpt4 key购买 nike

我有一个不需要特定字段作为主键的表。我可以添加一个自动递增 ID 字段,但它根本不会在数据库查询中使用...

我也可以将 UNIQUE KEY 设置为主键吗?

UNIQUE KEY 由两个配对的字段组成:

a VARCHAR(64) NOT NULL,
b VARCHAR(64) NOT NULL,
UNIQUE KEY uk_ab(a,b)

最佳答案

当然(不需要UNIQUE KEY):

PRIMARY KEY (a, b)

看看 documentation :

A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. The name of a PRIMARY KEY is always PRIMARY, which thus cannot be used as the name for any other kind of index.

A PRIMARY KEY can be a multiple-column index. However, you cannot create a multiple-column index using the PRIMARY KEY key attribute in a column specification. Doing so only marks that single column as primary. You must use a separate PRIMARY KEY(index_col_name, ...) clause.

关于php - 如何使 key 对成为主要 key 对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8376420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com