I am using the Microsoft.SqlServer.Management.Smo classes to script out SQL scripts for stored procedures, tables, views etc. I am doing this for putting them in source control.
Instead of the CREATE scripts for stored procedures, how can I get ALTER scripts for them? Is there an setting / option in the ScriptingOptions' properties?
Generate a Script in the SQL Server Management Studio Open SQL Server Management Studio (SSMS) Expand Databases. Select the database to script. Right-click on the database and select Tasks > Generate Scripts.
then simply use.
foreach (string line in script)
{
string l = line.Replace("CREATE FUNCTION", "ALTER FUNCTION");
}
Ta Da. :).
The StoredProcedure
class has a method that creates ALTER
statements.
https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.storedprocedure.scriptheader(v=sql.120).aspx
Usage
var sprocHeader = sproc.ScriptHeader(forAlter: true);
var sprocBody = sproc.TextBody;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With