Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个有列的表
现在我希望在 cid、cemail、cfax 中不应该有重复,因为我将这些都作为主键,但是如果只有一个值是不同的数据库接受数据,我希望它应该检查所有值我现在应该做什么?
您应该在这些字段中创建唯一索引。
就像一个简单的例子(未测试):
CREATE UNIQUE INDEX my_index ON my_table(cemail, cfax, cname);
CREATE TABLE `customers` ( `cid` int NOT NULL auto_increment, `cemail` varchar(123) NOT NULL, `cfax` varchar(123) NOT NULL, `cname` varchar(123) NOT NULL, PRIMARY KEY (`cid`), UNIQUE KEY `cemail` (`cemail`,`cfax`,`cname`) );