Vytalyi
Vytalyi

Reputation: 1695

Executing of large script in SQL Server 2008

I have a really big script (about 1GB) with UPDATE statements. Something like

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

What is the best way to execute this script? I suppose that I can't simply open it at text editor and run query...

Thanks in additional.

UPDATED

I need to run this script on remote SQL Server instance.

Upvotes: 1

Views: 1676

Answers (2)

Aram Beginyan
Aram Beginyan

Reputation: 294

this is will help you, it's worked very good for me

Bulk Update Data

Upvotes: 0

Jester
Jester

Reputation: 3329

execute it wih the osql utility Reference

Example:

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

you can also type for reference:

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]

For remote server but you need the sql utility installed on the machine you run this.

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

Upvotes: 4

Related Questions