Beispiel #1
0
        private string ScriptBase(Database db, string definition)
        {
            var before = ScriptQuotedIdAndAnsiNulls(db, false);
            var after  = ScriptQuotedIdAndAnsiNulls(db, true);

            if (!string.IsNullOrEmpty(after))
            {
                after = Environment.NewLine + "GO" + Environment.NewLine + after;
            }

            if (RoutineType == RoutineKind.Trigger)
            {
                after +=
                    $"{Environment.NewLine}{(Disabled ? "DISABLE" : "ENABLE")} TRIGGER [{Owner}].[{Name}] ON [{RelatedTableSchema}].[{RelatedTableName}]{Environment.NewLine}GO{Environment.NewLine}";
            }

            if (string.IsNullOrEmpty(definition))
            {
                definition = $"/* missing definition for {RoutineType} [{Owner}].[{Name}] */";
            }
            else
            {
                definition = RemoveExtraNewLines(definition);
            }

            var text = new StringBuilder();

            text.AppendLine();
            text.Append(ExtendedProperties.Script());
            text.AppendLine();

            var header = HeaderScriptCreate(Owner);

            return(header + before + definition + after + text.ToString());
        }
Beispiel #2
0
        public override string ScriptCreate()
        {
            var text = new StringBuilder();

            text.Append(HeaderScriptCreate(Owner));

            text.AppendLine($"CREATE {(IsType ? "TYPE" : "TABLE")} [{Owner}].[{Name}] {(IsType ? "AS TABLE " : string.Empty)}(\r\n");
            text.Append(Columns.Script());
            if (_constraints.Count > 0)
            {
                text.AppendLine();
            }
            foreach (var c in _constraints.OrderBy(x => x.Name).Where(c => c.Type != "INDEX"))
            {
                text.AppendLine("   ," + c.ScriptCreate());
            }
            text.Append(")");
            if (PartitionSQL != null)
            {
                text.AppendLine($" ON {PartitionSQL}");
            }

            text.AppendLine();
            text.Append(ExtendedProperties.Script());
            text.AppendLine();

            foreach (var c in _constraints.Where(c => c.Type == "INDEX"))
            {
                text.AppendLine(c.ScriptCreate());
                text.AppendLine();
            }
            return(text.ToString());
        }