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

  • 相关阅读:
    浏览器内核
    为什么一般请求可以下载文件,Ajax 请求就不能下载
    转 深入理解javascript原型和闭包(10)——this
    node读取文本文件时,去掉BOM
    AMD & CMD
    gulp requirejs Error: ENOENT: no such file or directory, open '/js/require_config.js', 一直报找不到require_config.js,坑死了
    [BZOJ3224]普通平衡树
    [NOIP2014D2]
    [NOIP2014D1]
    [NOIP2013D2]
  • 原文地址:https://www.cnblogs.com/sendling/p/1374625.html
Copyright © 2011-2022 走看看