怎么给一个表加个字段,字段值是一个以内的随机数
一个一百以内的随机数

解决方案 »

  1.   

    create table tb(id int identity,col1 int)alter table tb
      add rndcol int default cast(rand()*100 as int)
      
    insert into tb(col1) values(10)
    insert into tb(col1) values(20)select * from tbdrop table tb
      

  2.   


    create table tb(id int,name varchar(50))
    insert into tb select 1,'a'
    insert into tb select 2,'b'alter table tb add randnum intupdate tb set randnum= abs(checksum(newid()))%10select * from tb用rand()得用游标更新
      

  3.   

    update tb set randnum= abs(checksum(newid()))%100
    default  rand()?顶