xSQL.Schema.SqlServer Namespace > SqlDatabase Class > ReadSchema Method : ReadSchema() Method |
'Declaration Public Overloads Sub ReadSchema()
public void ReadSchema()
public: void ReadSchema();
using xSQL.Schema.Core; using xSQL.Schema.SqlServer; using xSQL.SchemaCompare.SqlServer; namespace xSQL.Sdk.SchemaCompare.Samples { class Test { public static void ReadDatabaseSchema() { SqlServer server; SqlDatabase database; SqlTable table; ScriptingOptions options; try { //--create the SQL Server object, connect using Windows authentication server = new SqlServer(@"(local)"); //--create the database object database = server.GetDatabase("AdventureWorks"); //--attach an handler to database.SchemaOperation event in order to get progress information during the schema read database.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation); //--read the database schema database.ReadSchema(); //--locate the Employee table table = database.SqlTables["HumanResources", "Employee"]; if (table != null) { //--set the script option to CREATE the object options = new ScriptingOptions(); options.CreateScript = true; options.DropScript = false; options.AlterScript = false; //--script the table Console.Write(table.GetScript(options)); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } private static void database_SchemaOperation(object sender, SchemaOperationEventArgs e) { //--exclude verbose messages if (e.Message.MessageType != OperationMessageTypeEnum.Verbose) Console.WriteLine(e.Message.Text); } } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2