0

I have a large (1.2GB) sql(server) script file which includes lots of stored procedures. I want to execute this large file. The first problem is I cannot open the file in SQL Server Management Studio. So, I tried the following code:

declare @FileName  varchar(255)
declare @SQLLoad   nvarchar(max)

-- Set the file to load SQL Script from
set @FileName = 'C:\ZarifBarDB.sql'

-- Create command to load and execute the file
set @SQLLoad =
N'declare @cmd varchar(max);
select @cmd = fd.col1
from openrowset(bulk ' + QUOTENAME(@FileName, '''') + ', SINGLE_NCLOB) as FD(col1);
exec (@cmd)'

-- Load file data and execute
exec (@SQLLoad)

I should delete all the "GO" statements in order to execute this query. But in this way, when execution reaches the "Create Procedure" commands, I get the following error:

'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.

What should I do?

MIIB
  • 1,849
  • 10
  • 21
  • Did you try [sqlcmd](http://technet.microsoft.com/en-us/library/ms162773(v=sql.105).aspx) utility? – TomT Feb 04 '14 at 14:59
  • Sorry for the late response. sqlcmd gives me the following error: HResult 0xE9, Level 16, State 1 Shared memory Provider: No process is on the other end of the pipe. – MIIB Feb 09 '14 at 08:03
  • Use command line: https://technet.microsoft.com/en-us/library/ms170572(v=sql.110).aspx – profimedica Sep 11 '17 at 22:08

0 Answers0