martinjw/dbschemareader

Generate SQL Create Scripts for existing tables

whibdev opened this issue · 2 comments

Is there a property or method to capture a create sql script for an existing table in a connected database? I've started looping through each table in the DatabaseSchema.Tables and writing out the column properties, but I'm thinking this functionality must already be built in (although I can't seem to find it). Any help would be great.

            var factory = new DdlGeneratorFactory(SqlType.SqlServer); //adjust database type
            var tableGenerator = factory.AllTablesGenerator(databaseSchema);
            tableGenerator.IncludeSchema = false;
            var ddl = tableGenerator.Write(); //string with CREATE TABLE statements + relationships+indices

This works for me