views:

1420

answers:

6

I use RedGate SQL data compare and generate a .sql file so i can run it on my local machine but the problem is the file is over 300mb and i can't do copy and paste because the clipboard won't able to handle it and when i try to open the file in sql management tool. it give me error compiling about the size.

is there a way to run large .sql file? The file basically contain data for two new tables.

+1  A: 

Run it at the command line with osql, see here:

http://metrix.fcny.org/wiki/display/dev/How+to+execute+a+.SQL+script+using+OSQL

BobbyShaftoe
+14  A: 

From the command prompt, start up sqlcmd:

sqlcmd -S <server> -i C:\<your file here>.sql -o

Just replace with the location of your SQL box and with the name of your script. Don't forget if you're using a SQL instance the syntax is:

sqlcmd -S <server>\instance.

Here is the list of all arguments you can pass sqlcmd:

Sqlcmd            [-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 screen width]
  [-a packetsize]        [-e echo input]        [-I Enable Quoted Identifiers]
  [-c cmdend]            [-L[c] list servers[clean output]]
  [-q "cmdline query"]   [-Q "cmdline query" and exit] 
  [-m errorlevel]        [-V severitylevel]     [-W remove trailing spaces]
  [-u unicode output]    [-r[0|1] msgs to stderr]
  [-i inputfile]         [-o outputfile]        [-z new password]
  [-f  | i:[,o:]] [-Z new password and exit] 
  [-k[1|2] remove[replace] control characters]
  [-y variable length type display width]
  [-Y fixed length type display width]
  [-p[1] print statistics[colon format]]
  [-R use client regional setting]
  [-b On error batch abort]
  [-v var = "value"...]  [-A dedicated admin connection]
  [-X[1] disable commands, startup script, enviroment variables [and exit]]
  [-x disable variable substitution]
  [-? show syntax summary]
Ray Booysen
A: 

Can you run it successfully using osql or sqlcmd?

devio
A: 

Your question is quite similar to this one

You can save your file/script as .txt or .sql and run it from Sql Server Management Studio (I think the menu is Open/Query, then just run the query in the SSMS interface). You migh have to update the first line, indicating the database to be created or selected on your local machine.

If you have to do this data transfer very often, you could then go for replication. Depending on your needs, snapshot replication could be ok. If you have to synch the data between your two servers, you could go for a more complex model such as merge replication.

EDIT: I didn't notice that you had problems with SSMS linked to file size. Then you can go for command-line, as proposed by others, snapshot replication (publish on your main server, subscribe on your local one, replicate, then unsubscribe) or even backup/restore

Philippe Grondier
Jack mentioned that he can't do it from SSMS as the file is too large.
Ray Booysen
I didn't read until the last words!
Philippe Grondier
A: 

The file basically contain data for two new tables.

Then you may find it simpler to just DTS (or SSIS, if this is SQL Server 2005+) the data over, if the two servers are on the same network.

If the two servers are not on the same network, you can backup the source database and restore it to a new database on the destination server. Then you can use DTS/SSIS, or even a simple INSERT INTO SELECT, to transfer the two tables to the destination database.

P Daddy
A: 

I believe there's a NUL required after that -o switch

Achilles