方法#1(全文):
CREATE TABLE `addresses` (
`id` int(10) unsigned NOT NULL auto_increment,
`mail` text NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `mail` (`mail`)
);
通过搜索找出存在:
SELECT * FROM addresses WHERE MATCH(email) AGAINST('"name@example.com"' IN BOOLEAN MODE)
或方法#2(唯一的varchar):
CREATE TABLE `addresses` (
`id` int(10) unsigned NOT NULL auto_increment,
`mail` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mail` (`mail`)
);
用插入找出存在:
INSERT INTO `addresses` (`id`, `mail`) VALUES (NULL , 'name@example.com');
如果失败则存在:
#1062 - Duplicate entry 'name@example.com' for key 2
哪种方法更适合找出数千行中存在的邮件地址?