SQL2005CTE做无标识重复记录删除,让你的sql看起来更简单

来源:互联网 发布:电脑朗读软件 编辑:程序博客网 时间:2024/05/16 19:08
有些表设计没有标识,没有主键,删除起来一直是个麻烦的事情,而CTE的运用却让这件事情变得简单。create table CreDelete (id int identity(1,1),name varchar(10))goinsert into CreDelete       select '张三' as nameunion all  select '王2'union all  select '张三'union all  select '王2'union all  select '张1'union all  select '张2'union all  select '张1'union all  select '张2'goselect * from CreDelete;with mycte as(select ROW= ROW_NUMBER() over(PARTITION  by name order by id),* from CreDelete)delete from mycte where ROW>1

原创粉丝点击