Created
August 2, 2016 22:22
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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