zoukankan      html  css  js  c++  java
  • 删除数据库重复数据一方法

    今天遇到重复数据问题,我这里主要把主键自动增长去掉先,不然有这个"仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 '' 中为标识列指定显式值"问题。

    创建表

    Code

    插入数据

    Code

    创建临时表

    Code

    这里测试Title重复的数据

    --新建一个临时表的索引,并“忽略重复的值”,xxx作为唯一表识值字段
    CREATE  UNIQUE  INDEX [temp] ON [dbo].[testchongfu_temp]([Title]WITH  IGNORE_DUP_KEY  ON [PRIMARY]
    GO


    --把原表的数据导入临时表,XXX为原表名
    insert into testchongfu_temp Select * from testchongfu


    --清空原表,并将临时表中的数据导回原表,最后删除临时表
    delete testchongfu

    insert into testchongfu select * from testchongfu_temp
    drop table testchongfu_temp


     原参考地址:http://www.cnblogs.com/idotnet8/articles/1330768.html

  • 相关阅读:
    mojoportal学习——文章翻译之SmartCombo
    windows froms 程序打包 (转载)
    [笔记]LCD1602 Display Experiment
    [笔记] JLink V8固件烧录指导
    [笔记]NiosII之Count Binary
    [笔记]DE2115 LCD1602字符的显示
    [笔记]What is HDBaseT
    [笔记]Inrush Current Case
    [笔记]远传中继的实现
    [笔记]RunningLED Experiment
  • 原文地址:https://www.cnblogs.com/sendling/p/1374625.html
Copyright © 2011-2022 走看看