mysql UNIQUE的条件
伊谢尔伦
伊谢尔伦 2017-04-17 15:32:49
0
2
678
ALTER TABLE  `table` ADD  `unionid` VARCHAR( 255 ) NOT NULL

然后设置唯一索引

ALTER TABLE  `table` ADD UNIQUE (
`unionid`
)

提示

1062 - Duplicate entry '' for key 'unionid'

请问这是为什么呢?

伊谢尔伦
伊谢尔伦

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

reply all(2)
Ty80

The first SQL sentence: You added a table column to the unionid table, and it is a non-empty string, so the initial value is an empty string '';

Second SQL sentence: You establish a unique constraint on the table column of the unionid table, but the premise of the unique constraint is that the values ​​of the unionid column are not repeated. However, all values ​​of the unionid column are null characters. string '', so it will report Duplicate entry '' for key 'unionid'.

Solution: First correct the value of unionid to be non-repeating and then add a unique constraint to the column.

洪涛

Go directly to the database to operate. When you add an index, there will be a command prompt, so you will know what is wrong

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!