Exemplo n.º 1
0
        private void CreateBackupFile(DBDatabase database, string pathToFile)
        {
            var curDate = DateTime.Now;

            using (var sqlFile = new StreamWriter(pathToFile))
            {
                sqlFile.WriteLine(database.GetCreationQuery());
                sqlFile.WriteLine();
                sqlFile.WriteLine($"USE [{database.Name}]");
                sqlFile.WriteLine("GO");
                sqlFile.WriteLine();

                this.WriteSchemas(database.Schemas, sqlFile);
                sqlFile.WriteLine();

                this.WriteTablesCreation(database.Tables, sqlFile);
                sqlFile.WriteLine();

                this.WriteViews(database.Views, sqlFile);
                sqlFile.WriteLine();

                this.WriteSynonyms(database.Synonyms, sqlFile);
                sqlFile.WriteLine();

                this.WriteProcedures(database.Procedures, sqlFile);
                sqlFile.WriteLine();

                this.WriteFunctions(database.Functions, sqlFile);
                sqlFile.WriteLine();

                this.WriteSequences(database.Sequences, sqlFile);
                sqlFile.WriteLine();

                this.WriteTableData(database.Tables, sqlFile);
                sqlFile.WriteLine();

                this.WriteConstraints(database.Constraints, sqlFile);
                sqlFile.WriteLine();

                this.WriteTriggers(database.Tables, sqlFile);
                sqlFile.WriteLine();
            }
        }