Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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