2012-11-20 29 views
1

我有一个非常大的脚本(大约1GB),其语句为UPDATE。类似于在SQL Server 2008中执行大型脚本

UPDATE Table1 SET Col1 = 'Some text 1' WHERE ID = 1 
UPDATE Table1 SET Col1 = 'Some text 2' WHERE ID = 2 
-- and so on 

执行此脚本的最佳方法是什么?我想,我不能简单地在文本编辑器打开它,并运行查询...

谢谢额外。

已更新

我需要在远程SQL Server实例上运行此脚本。

+0

所以你不必访问服务器? – Jester

回答

4

执行它王氏osql工具Reference

实施例:

osql -E -i C:\MyFolder\MyScript.sql -o C:\MyFolder\MyOutput.rpt 

还可以键入以供参考:

osql -? 



usage: osql    [-U login id]   [-P password] 
    [-S server]   [-H hostname]   [-E trusted connection] 
    [-d use database name] [-l login timeout]  [-t query timeout] 
    [-h headers]   [-s colseparator]  [-w columnwidth] 
    [-a packetsize]  [-e echo input]  [-I Enable Quoted Identifiers] 
    [-L list servers]  [-c cmdend]   [-D ODBC DSN name] 
    [-q "cmdline query"] [-Q "cmdline query" and exit] 
    [-n remove numbering] [-m errorlevel] 
    [-r msgs to stderr] [-V severitylevel] 
    [-i inputfile]   [-o outputfile] 
    [-p print statistics] [-b On error batch abort] 
    [-X[1] disable commands [and exit with warning]] 
    [-O use Old ISQL behavior disables the following] 
     <EOF> batch processing 
     Auto console width scaling 
     Wide messages 
     default errorlevel is -1 vs 1 
    [-? show syntax summary] 

对于远程服务器,但需要安装在所述SQL实用程序你运行这个机器。

osql -S <instance name> -U <username> -P <password> -i C:\MyFolder\MyScript.sql -o C:\MyFolder\MyOutput.rpt 
+0

你能写出我可以如何指定servername(不是本地),初始数据库/目录,用户名和密码吗? – Vytalyi

+0

已更新替换与相应的数据 – Jester

+0

osql -U sa -S SERVERNAME -P PASSWORD -i C:\ MyFolder \ MyScript.sql -o C:\ MyFolder \ MyOutput1.rpt –

相关问题