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?