create table tb(a int,id int) insert into tb select 1,4560 union all select 2,null union all select 3,1540 union all select 4,4561 union all select 5,null goupdate tb set id = (select cast(ceiling(rand(checksum(newid()))*10000) as int)) where id is nullselect * from tbdrop table tb /* a id ----------- ----------- 1 4560 2 372 3 1540 4 4561 5 7165(5 行受影响)
create table tb(a int,id int)
insert into tb
select 1,4560 union all
select 2,null union all
select 3,1540 union all
select 4,4561 union all
select 5,null
goupdate tb
set id = (select cast(ceiling(rand(checksum(newid()))*10000) as int))
where id is nullselect *
from tbdrop table tb
/*
a id
----------- -----------
1 4560
2 372
3 1540
4 4561
5 7165(5 行受影响)