如何复制一部分数据,超过一万条,不加条件,就是随意从某部分开始,如可否按行号?

解决方案 »

  1.   

    select top (行数)
    from tb
      

  2.   

    行号用row_number()可以得到,然后between 1 and 100000即可
      

  3.   

    游标不推荐使用。消耗资源多不说,还会消耗相对较多的时间。 如果插入数据较多可以考虑用while判断,分批次进行插入处理,比如一次插入2000条数据。 
      

  4.   

    楼主,如果方便,可否给予相关的语句,谢谢,我是个sql初学者。
      

  5.   

    if object_id('[NewTable]') is not null drop table [NewTable]
    goif object_id('[TB]') is not null drop table [TB]
    go
    create table [TB] (id int,name nvarchar(2))
    insert into [TB]
    select 1,'A' union all
    select 2,'B' union all
    select 3,'C'select * from [TB]with TT
    as(
    select [rowno] = row_number() over (order by id),id,[name]
    from TB)select id,[name]
    into NewTable
    from TT
    where rowno between 1 and 2
    select * from NewTable/*
    id          name
    ----------- ----
    1           A
    2           B(2 行受影响)
    */