数据表位A_ziliao 列为 sheng
如何批量将:上海、北京、重庆、天津
这4个值随机写进去?
急求,会追加分
将这些随机改成上海、北京、重庆、天津的一个
急!批量修改SQL数据库的某一列,随机赋予几个值
答案:3 悬赏:0
解决时间 2021-02-23 15:15
- 提问者网友:回憶丶初
- 2021-02-22 16:46
最佳答案
- 二级知识专家网友:怪咖小青年
- 2021-02-22 17:28
数据表位A_ziliao 有一标志id
首先建立一个过渡表(id,地名)
用游标查询数据表A_ziliao记录id
更改列 sheng 为随机值
declare @fid int,@nn int
declare cursor3 cursor for --定义游标cursor3
select id from A_ziliao --使用游标的对象(跟据需要填入select文)
open cursor3 --打开游标
fetch next from cursor3 into @fid
while @@fetch_status=0 --判断是否成功获取数据
begin
set @nn =4*rand +1'随机id
update A_ziliao set sheng=(select 地名 from 过渡表 where id= @nn )where id=@fid
fetch next from cursor3 into @fid --将游标向下移1行
end
close cursor3 --关闭游标
deallocate cursor3
首先建立一个过渡表(id,地名)
用游标查询数据表A_ziliao记录id
更改列 sheng 为随机值
declare @fid int,@nn int
declare cursor3 cursor for --定义游标cursor3
select id from A_ziliao --使用游标的对象(跟据需要填入select文)
open cursor3 --打开游标
fetch next from cursor3 into @fid
while @@fetch_status=0 --判断是否成功获取数据
begin
set @nn =4*rand +1'随机id
update A_ziliao set sheng=(select 地名 from 过渡表 where id= @nn )where id=@fid
fetch next from cursor3 into @fid --将游标向下移1行
end
close cursor3 --关闭游标
deallocate cursor3
全部回答
- 1楼网友:茫然不知崩溃
- 2021-02-22 17:59
直接建个页面搞啊,
- 2楼网友:心与口不同
- 2021-02-22 17:43
你好!
这个表中有没有其它列作参考?如果还有其它列,表中是否已经有了记录?还是只是要往一个空表中加入上述内容?
如果对你有帮助,望采纳。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯