-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here is a small piece of code I created to clone a database but only using the first 10 records for each table #151
Comments
There is nothing like that on the web, i searched and nothing , even the very expensive tools don't do that you are welcome to add it to the project under |
you may want to add it (with a check mark to be checked) to the project -- For example from a table called RobotLogic, you may need all of the records, , also you may need all data for tables where the table name ends with the word "Type", but then for other tables you only need a few rows of data, for example, you may just need one record for the table called AuditLog, and 15 records for the tables that meet another condition, etc. Using this awesome project you can create all of your logic in C#, and with that logic generate the SQL server script then run the T-SQL script on MS SQL Console. |
We use this to generate scripts (which are executed by other db admin tools), to clone/refresh databases using (var connection = new SqlConnection(connectionString))
{
var dr = new DatabaseReader(connection);
var schema = dr.ReadAll();
//custom extension to clear out not required tables using RemoveTable()
schema.RemoveTables(TableFilter);
var factory = new DdlGeneratorFactory(SqlType.SqlServer);
var tableGenerator = factory.AllTablesGenerator(schema);
tableGenerator.IncludeSchema = false;
var ddl = tableGenerator.Write();
var scriptWriter = new DatabaseSchemaReader.Data.ScriptWriter
{
PageSize = 200 //how many records per table
};
var dml = new StringBuilder();
foreach (var table in SchemaTablesSorter.TopologicalSort(schema))
{
dml.AppendLine(scriptWriter.ReadTable(table, connection)); //insert sql
}
File.WriteAllText(pathDdl, ddl);
File.WriteAllText(pathDml, dml.ToString());
} The CopyToSQLite project contains similar code to clone say a SqlServer db to SQLite - again, I've used bits of that to clone to other SqlServer. |
@martinjw |
//
var sqlQueryStr = "";
var sqlQueryTruncate = "";
foreach (var table in schema.Tables)
{
// I dont want to clone tables that meet this condition
var goodTable = false;
if (!table.Name.StartsWith(""))
{
goodTable = true;
The text was updated successfully, but these errors were encountered: