现有一表,已有数据过万,我想在此表加一个列,用于记录每条记录所在表的行数,请问各们有没什么好办法,谢谢,谢谢

解决方案 »

  1.   

    select *,identity(int,1,1) as 行数 into Table2 from table1
      

  2.   

    create table tb(name varchar(10))
    insert into tb select 'aa'
    insert into tb select 'vaa'
    insert into tb select 'aad'
    insert into tb select 'ada'
    goalter table tb add 行数 int identity(1,1)
    goselect * from tbdrop table tb
      

  3.   

    eddy8863(西北狂) 你的方法不太好吧,那我不是又要重新建个表,xeqtr1982(vesslan) 标识列怎么运用
      

  4.   

    --你可以运行一下看看
    create table tb(name varchar(10))
    insert into tb select 'aa'
    insert into tb select 'vaa'
    insert into tb select 'aad'
    insert into tb select 'ada'
    goselect * from tb
    goalter table tb add 行数 int identity(1,1)
    goselect * from tbdrop table tb
      

  5.   

    没把握的话,可以新建一个和你的数据表完全一样的表测试一下select * into 表2 from 表1
      

  6.   

    alter table tb add 行数 int identity(1,1)
    这里的"行数"是你新增的列名,可以修改为其他
    因为这个列是个标识列,所以当数据增加时可以自动增加
    在以后向表中添加数据时,不能向这个列插入值,否则会提示错误
      

  7.   

    xeqtr1982(vesslan) 的方法不错,谢谢,谢谢!
      

  8.   

    xeqtr1982(vesslan) ( ) 信誉:100 
    同意