场景:比如有两个表,一个设备总表vms,一个是部份机器的IP列表conf,需要将设备总表里面的一列系统管理员设置为小明

vms表当中IP地址的列名为IP初始地址,conf的ip地址列名为ip,游标的定义如下:

DECLARE selconf CURSOR
for
select ip from conf
GO
open selconf
declare @ip varchar(50)
fetch next from selconf into @ip
while @@FETCH_STATUS=0

begin
#print(@ip)
update vms set [系统管理员]='小明' where [IP初始地址]=@ip
fetch next from selconf into @ip
END
close selconf
DEALLOCATE selconf

 

 

 

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐