mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 01:25:40 -05:00
Update docs (#200)
This is a documentation-only update so automerging. Please review the commit if there are any follow-ups requested. * Update .gitignore for docfx genertated files * Update documenation (part 1) * Update docs and add some samples * More doc updates
This commit is contained in:
45
docs/samples/smo/net45/Scripting/Program.cs
Normal file
45
docs/samples/smo/net45/Scripting/Program.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SmoSdkSamples
|
||||
{
|
||||
// This application demonstrates how to script out a sample database without dependencies and iterate through the list to display the results.
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Connect to the local, default instance of SQL Server.
|
||||
Smo.Server srv = new Smo.Server();
|
||||
// database name
|
||||
Console.WriteLine("Enter database name for scripting:");
|
||||
string dbName = Console.ReadLine();
|
||||
// Reference the database.
|
||||
Database db = srv.Databases[dbName];
|
||||
// Define a Scripter object and set the required scripting options.
|
||||
Scripter scripter = new Scripter(srv);
|
||||
scripter.Options.ScriptDrops = false;
|
||||
// To include indexes
|
||||
scripter.Options.Indexes = true;
|
||||
// to include referential constraints in the script
|
||||
scripter.Options.DriAllConstraints = true;
|
||||
// Iterate through the tables in database and script each one. Display the script.
|
||||
foreach (Table tb in db.Tables)
|
||||
{
|
||||
// check if the table is not a system table
|
||||
if (tb.IsSystemObject == false)
|
||||
{
|
||||
Console.WriteLine("-- Scripting for table " + tb.Name);
|
||||
// Generating script for table tb
|
||||
System.Collections.Specialized.StringCollection sc = scripter.Script(new Urn[] { tb.Urn });
|
||||
foreach (string st in sc)
|
||||
{
|
||||
Console.WriteLine(st);
|
||||
}
|
||||
Console.WriteLine("--");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user