删除重复列(注:表的ID数据类型是uniqueidentifier)

来源:互联网 发布:怎么看网络计划图 编辑:程序博客网 时间:2024/06/05 01:11



平常我们会这样做:

  delete from T_users where id not in (select MAX(id) from T_users group by name)

  但是发现出错啦  操作数数据类型 uniqueidentifier 对于 max 运算符无效。

  所以当id的数据类型不是uniqueidentifier时,可以用上述方法

那该怎么办?下面的方法你可以尝试一下

    select identity(int,1,1) as Aid,* into #temp from T_users
   delete from T_users
   delete from #temp where Aid not in(select MAX(Aid) from #temp group by name)
    insert into T_users(id,name) select id,name from #temp



原创粉丝点击