How to create ALTER scripts instead of CREATE scripts using SMO (server control object)

I am using Microsoft.SqlServer.Management.Smo classes for script from SQL scripts for stored procedures, tables, views, etc. I do this in order to put them in the original management.

Instead of CREATE scripts for stored procedures, how can I get ALTER scripts for them? Is there a / option parameter in ScriptingOptions properties ?

+3
source share
5 answers

There seems to be no settings for ALTER scripts. A property with ScriptingOptions.ScriptDrops as true creates drop statements. The disadvantage of this is that permissions had to be reassigned.

The completion of this question.

+1
source

Take a look at DBSourceTools .

This is a GUI tool for scripting all objects in an SQL database to disk, in particular for managing databases from source code. Back-end uses SMO.

+1
source
  • SMO #
  • .

    foreach (string line in script)
                {
                    string l = line.Replace("CREATE FUNCTION", "ALTER FUNCTION");
                }
    
  • .:).

+1

. toSP - SP. "TO" , Create(), Alter() StoredProcedure spT

If toSP = "" Then  ' Empty
    spT.Create()
Else
    spT.Alter()
End If
0

StoredProcedure , ALTER.

https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.storedprocedure.scriptheader(v=sql.120).aspx

Using

var sprocHeader = sproc.ScriptHeader(forAlter: true);
var sprocBody = sproc.TextBody;
0
source

Source: https://habr.com/ru/post/1752680/


All Articles