1.請問怎樣刪除某數據表的前n條記錄.
2.查詢某表的特殊行,取代原來的數據表

解决方案 »

  1.   

    1.delete top N from tb
    2.select * into xx from tb where 很特殊=true
      truncate table tb
      insert into tb select * from xx
      

  2.   

    delete a
    from ta a
    where exists(select top N * from ta where a.id = id)
    update a
    set col = b.col
    from a
    right join b
    on b.id = a.id
     where b......... = ??
      

  3.   

    create table tb (id int)
    insert tb select 1 union all select 2 union all select 3set rowcount 1  --将1改为你的n
    delete from tb
    set rowcount 0select * from tbdrop table tb
    第二问,不明你意。
      

  4.   

    --1
    delete from tab
    where id in (select top n id from tab order by id)
      

  5.   

    select identity(int,1,1) as id ,* into tmp from tablename drop table tmp where id <=n   ---- 請問怎樣刪除某數據表的前n條記錄. sp_rename 'tmp','tablename'
      

  6.   

    ---如果没有序号列!
    select identity(int,1,1) as id ,* into tmp from tablename drop table tmp where id <=n   ---- 請問怎樣刪除某數據表的前n條記錄. drop table tablenamesp_rename 'tmp','tablename'
      

  7.   

    delete top N from tb
    這一行不可以執行啊
      

  8.   

    delete a
    from ta a
    where exists(select top N * from ta where a.id = id) 
    這一行肯定不行id要是主鍵才行