Programmatically generate a script for all objects in the database

To automatically build an installation that generates customization for an application using Microsoft SQL Server, I am currently evaluating whether the following is possible:

I want to programmatically (CMD script or C # code) execute the " Generate Scripts " function in a database accessible from Microsoft SQL Server Management Studio 2008.

those. call some code and have all the objects (tables, SP, restrictions, etc.) of the specified database in the form of an SQL script.

I currently need a structure, not data.

Question : Is it possible to achieve this goal?

+3
source share
5 answers

I wrote SMOscript , a command line tool for scripting all objects in one file or one file for all objects.

The MSSQL Generate Scripts function usually does not consider references and dependencies to determine the sequence of objects (at least, this was the case with 2000 and 2005)

+5
source

I have used http://www.codeplex.com/ScriptDB with great success.

+3
source

You should be able to do this in managed code using SMO

+2
source

You can invoke the standard select clause (for example, using ADO.NET) over the sysobjects view .

+1
source

Microsoft also released a tool called "mssql-scripter". It can be found here: mssql-scripter

+1
source

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


All Articles