我有很多平凡的更新语句,我必须通过PLSQL和MSSQL,它需要大量的编辑。我通常会将数据拉入excel而不是在notepad ++中重新格式化。这是非常耗时的,我想知道是否有任何解决方案吗?
UPDATE ATGSITES SET IPADDRESS = 'xxx' WHERE OWNSITEID = '270789'
UPDATE ATGSITES SET IPADDRESS = '1yyy' WHERE OWNSITEID = '270506'
UPDATE ATGSITES SET IPADDRESS = '158568' WHERE OWNSITEID = '27745'
X(35353)更新声明
答案 0 :(得分:0)
也许您可以创建更新表并执行单个连接
UPDATE ATGSITES SET IPADDRESS = B.IPADDRESS
From ATGSITES A
Join NewTable B on A.OWNSITEID = B.OWNSITEID
NewTable的结构为OWNSITEID和IPADDRESS
我还会在OWNSITEID
上添加一个索引答案 1 :(得分:0)
在Ms Sql Server中
将数据保存在以逗号(如该格式)分隔的CSV文本文件中
IPADDRESS , OWNSITEID
xxx ,270789
1yyy ,270506
158568 ,27745
......
...........
假设要更新的表名为:users_ip
运行以下脚本以从文本文件
更新表-- update table users_ip from csv file delimited wth , and first row is header
-- create temp table for loading the text file
CREATE TABLE #tmp_x (IPADDRESS nvarchar (10),OWNSITEID nvarchar(10))
go
-- import the csv file
BULK INSERT #tmp_x
FROM 'c:\temp\data.txt' --CSV file with header delimited by ,
WITH ( FIELDTERMINATOR =',',rowterminator = '\n',FIRSTROW = 2 )
go
update u
set u.IPADDRESS = t.IPADDRESS
from users_ip u
join #tmp_x t on t.OWNSITEID = u.OWNSITEID
//drop the temp table
drop table #tmp_x