关于mysql primary key的解释
伊谢尔伦
伊谢尔伦 2017-04-17 13:35:33
0
5
997

我看网上说primary key 就等于唯一+不为空,而且一个表里只能有一个primary key,但是我在数据库创建表的时候PRIMARY KEY (username,bm_URL),这样不就2个主键了?而且我insert数据的时候 username 有重复'admin',并没有报错啊,怎么解释第一句话呢

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(5)
Peter_Zhu

What you write like that is a joint primary key. Username can be repeated, but under the same username, bm_URL can be different

洪涛

The meaning of primary key is the unique identification of a record, similar to the ID of an ID card.
The primary key can be a field or a combination of multiple fields. If it is a field, the primary keys of different records or different rows are not allowed to be repeated; if it is a combination of multiple fields, the combination of these fields is not allowed to be the same. .
So in your case, as long as the username and bm_URL are not the same at the same time, there will be no conflict.

Peter_Zhu

There can only be one primary key in a table. The primary key is self-increasing and not empty. There can be multiple uniques in the table. It is recommended that you use visual phpadmin or Navicat

迷茫

Multiple primary keys are called joint primary keys, which can also be called joint primary keys. You can imagine it as a product order table. The user ID in the record can be repeated, and the user ID and order number must be unique together.

黄舟

The index (index or key) in the database is not specific to one column, so a key can be composed of multiple columns (such as the username and bm_URL you set here). Therefore, the uniqueness of the primary key means that all the columns it contains cannot be repeated together. It does not matter if you repeat the username alone~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!