Skip to content

Instantly share code, notes, and snippets.

@billinkc
Created August 2, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billinkc/d40086cb800c17a70e03d74b9b93c391 to your computer and use it in GitHub Desktop.
Save billinkc/d40086cb800c17a70e03d74b9b93c391 to your computer and use it in GitHub Desktop.
Biml Export table definitions. This script uses the extension methods GetDatabaseSchema and GetDropAndCreateDdl to reverse engineer a database model into memory and then emit sql files with the proper drop and create table scripts. For more info, see http://www.cathrinewilhelmsen.net/2015/07/12/biml-extension-methods-getdatabaseschema/
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#@ template tier="1" #>
<#@ import namespace="Varigence.Biml.CoreLowerer.SchemaManagement" #>
<#@ import namespace="System.IO" #>
<#
var schema = new List<string>{"CMS"};
var ODSCM = RootNode.OleDbConnections["ODS"];
var ODSDB = ODSCM.GetDatabaseSchema(schema, null, ImportOptions.None);
string fileNameTemplate = @"C:\Users\fellowsb\Documents\ODSDB\{0}_{1}.sql";
string currentFileName = string.Empty;
foreach (var table in ODSDB.TableNodes)
{
currentFileName = string.Format(fileNameTemplate, table.Schema.Name, table.Name);
System.IO.File.WriteAllText(currentFileName, table.GetDropAndCreateDdl());
}
#>
</Biml>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="ODS" ConnectionString="Data Source=localhost\DEV2014;Initial Catalog=ODS;Provider=SQLNCLI11.0;Integrated Security=SSPI;"/>
</Connections>
</Biml>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment