本帖最后由 lovewangya 于 2010-09-24 11:37:50 编辑

解决方案 »

  1.   

    标题加索引
    select 1 from table where title='测试一下标题'
      

  2.   

    标题TITLE字段上添加唯一索引。然后你可以直接使用 inser into ... on duplicate update关于on duplicate update的详细说明请参考MYSQL手册中的说明和例子MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  3.   

    这个可以做到 
    insert ignore into test1(id,name,type)(select id,name,type from test2);就举个例子 使用关键字ignore就可以了
      

  4.   

    IGNORE INTO
    判断是否存在,存在不插入,否则插入。很容易理解,当插入的时候,违反唯一性约束,MySQL不会尝试去执行这条语句。
      

  5.   

    你这个效率不太高吧?还是会去查询一次数据库!
    这样为title字段在添加一个字段为title的hash值,然后给hash值添加唯一索引,这样先更具hash去查下数据库表里面时候有这个hash值,我想这样会快一点,以前我们做的提案系统就是这样做的,呵呵!
      

  6.   

    alter table Ta
    ADD UNIQUE index_title (title);然后再照3楼的办法,忽略会导致重复关键字错误的记录。
      

  7.   

    alter table Ta
    ADD UNIQUE index_title (title);索引文件甚至比数据文件大。
    不可取数据表应该如此
    id(int(10) unsigned auto_increment) class(tinyint(1)) title_crc32(int(11)) title(varchar(255))alter table tab_name add index crc32(title_crc32);
    插入时 仍然先查询一次,select * from tab_name where title_crc32='new_title_crc32' and title='new_title';