exec('alter table tb add sid int identity(1,1)')  
delete a from tb a where not exists(select 1 from tb where id=a.id and sid<a.sid) 
alter table tb drop column sid  

解决方案 »

  1.   

    exec('alter table tb add sid int identity(1,1)')  
    exec('delete a from tb a where not exists(select 1 from tb where id=a.id and sid<a.sid') 
    exec('alter table tb drop column sid')  
      

  2.   

    楼主,修改表,必须立即执行(即后面来go,我给你的语句就加了go),如果放在存储过程,则按楼上的处理(用动态SQL)
      

  3.   

    TO VIVI:
    exec('delete a from tb a where not exists(select 1 from tb where id=a.id and sid<a.sid') 少了一个括号,