Hello, I want to use multiple SQL statements in my migrations. When I try to use the GO keyword, it shows syntax errors, as I believe this is not a word that works outside of SQL Server Management Studio. How can I write multiple statements, like a batch
of stored procedures, through the Sql(); method in my Up and Down methods. When I run Update-Database I want all my statements to run.
r2007
Member
4 Points
21 Posts
Executing multiple SQL Statements in a migration
Nov 25, 2012 10:51 PM|LINK
Hello, I want to use multiple SQL statements in my migrations. When I try to use the GO keyword, it shows syntax errors, as I believe this is not a word that works outside of SQL Server Management Studio. How can I write multiple statements, like a batch of stored procedures, through the Sql(); method in my Up and Down methods. When I run Update-Database I want all my statements to run.
thanks
ignatandrei
All-Star
137690 Points
22151 Posts
Moderator
MVP
Re: Executing multiple SQL Statements in a migration
Nov 26, 2012 03:15 AM|LINK
separate with
;
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Executing multiple SQL Statements in a migration
Nov 26, 2012 06:42 AM|LINK
Hello,
You can also try to use Stored Procdure to escapulate them together to call the SP directly.
r2007
Member
4 Points
21 Posts
Re: Executing multiple SQL Statements in a migration
Nov 26, 2012 07:40 AM|LINK
The only way I have found to separate the statements was to use a form like:
EXEC sp_executesql N'
--SQL Statement 1
';
EXEC sp_executesql N'
--SQL Statement n
';
This was the only way I found to do it, to have my SQL in a string executed by SQL.