对于结合唯一的疑惑

WBOY
Release: 2016-06-13 12:04:32
Original
837 people have browsed it

对于组合唯一的疑惑

<br />create table `table` if not exists{<br />  `a` varchar(30) not null<br />  `b` tinyint(1) not null default 0<br />}<br />
Copy after login

这两个字段一定不能同时重复,故我设置了组合唯一。
现在问题来了,因为每次插入数据时,·a·有可能为空,那就会导致第二条·a·为空的数据因为重复而无法插入。
请教大家有什么解决方法吗?是否只能把`a`设为null?
------解决方案--------------------
a 为空时, b 总有值吧?
------解决方案--------------------
你a字段可能為空,B恆等於0,邏輯上就已經是有問題了。
已經不是組合唯一了,因為B恆等。然後a如果是空就重複了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
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!