Beispiel #1
0
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(_name))
            {
                return(_name);
            }

            string keyname = "IX";

            if (Unique)
            {
                keyname = "UIX";
            }

            var columnClause = string.Join("_", ColumnName.ToArray());

            columnClause = String.Format("_{0}", columnClause);

            var name = string.Format("{0}_{1}_{2}{3}", keyname, SchemaName, TableName, columnClause);

            if (string.Equals(SchemaName, "dbo", StringComparison.InvariantCultureIgnoreCase))
            {
                name = string.Format("{0}_{1}{2}", keyname, TableName, columnClause);
            }

            return(name);
        }
        public override string ToQuery()
        {
            var clusteredClause = "";

            if (Clustered)
            {
                clusteredClause = " clustered";
            }

            var allOptions = new List <string>(Options);

            if (FillFactor > 0)
            {
                allOptions.Add($"fillfactor = {FillFactor}");
            }

            var optionClause = "";

            if (allOptions.Count > 0)
            {
                optionClause = $" with ({string.Join(", ", allOptions.ToArray())})";
            }

            var fileGroupClause = "";

            if (!string.IsNullOrEmpty(FileGroup))
            {
                fileGroupClause = $" on {FileGroup}";
            }

            var columnClause = string.Join("], [", ColumnName.ToArray());

            return($"alter table [{SchemaName}].[{TableName}] add constraint [{Name}] unique{clusteredClause} ([{columnClause}]){optionClause}{fileGroupClause}");
        }
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(_name))
            {
                return(_name);
            }

            string keyname;

            switch (Type)
            {
            case ConstraintType.Default:
                keyname = "DF";
                break;

            case ConstraintType.PrimaryKey:
                keyname = "PK";
                break;

            case ConstraintType.Check:
                keyname = "CK";
                break;

            case ConstraintType.UniqueKey:
                keyname = "AK";
                break;

            default:
                keyname = "DF";
                break;
            }

            var columnClause = string.Join("_", ColumnName.ToArray());

            columnClause = String.Format("_{0}", columnClause);

            if (Type == ConstraintType.PrimaryKey)
            {
                columnClause = "";
            }

            var name = string.Format("{0}_{1}_{2}{3}", keyname, SchemaName, TableName, columnClause);

            if (string.Equals(SchemaName, "dbo", StringComparison.InvariantCultureIgnoreCase))
            {
                name = string.Format("{0}_{1}{2}", keyname, TableName, columnClause);
            }

            return(name);
        }
Beispiel #4
0
        public override string ToQuery()
        {
            var sourceColumns = string.Join("],[", ColumnName.ToArray());
            var refColumns    = string.Join("],[", ReferencesColumnName.ToArray());

            var onDeleteClause = "";

            if (!string.IsNullOrEmpty(OnDelete))
            {
                onDeleteClause = string.Format("on delete {0}", OnDelete);
            }

            var onUpdateClause = "";

            if (!string.IsNullOrEmpty(OnUpdate))
            {
                onUpdateClause = string.Format("on update {0}", OnUpdate);
            }

            var notForReplicationClause = "";

            if (NotForReplication)
            {
                notForReplicationClause = "not for replication";
            }

            var withNoCheckClause = "";

            if (WithNoCheck)
            {
                withNoCheckClause = " with nocheck";
            }

            return
                (string.Format(
                     "alter table [{0}].[{1}]{10} add constraint [{2}] foreign key ([{3}]) references [{4}].[{5}] ([{6}]) {7} {8} {9}",
                     SchemaName, TableName, Name, sourceColumns, ReferencesSchemaName, ReferencesTableName,
                     refColumns, onDeleteClause, onUpdateClause, notForReplicationClause, withNoCheckClause));
        }
Beispiel #5
0
        public override string ToQuery()
        {
            var clusteredClause = "clustered";

            if (NonClustered)
            {
                // ReSharper disable once StringLiteralTypo
                clusteredClause = "nonclustered";
            }

            var optionClause = "";

            if (!(Options == null || Options.Count == 0))
            {
                optionClause = string.Join(", ", Options.ToArray());
                optionClause = $" with ( {optionClause} )";
            }

            var columnClause = string.Join("], [", ColumnName.ToArray());

            return
                ($"alter table [{SchemaName}].[{TableName}] add constraint [{Name}] primary key {clusteredClause} ([{columnClause}]){optionClause}");
        }
        public override string ToQuery()
        {
            var uniqueClause = "";

            if (Unique)
            {
                uniqueClause = " unique";
            }

            var clusteredClause = "";

            if (Clustered)
            {
                clusteredClause = " clustered";
            }

            var optionsClause = "";

            if (Options.Count > 0)
            {
                optionsClause = string.Join(", ", Options.ToArray());
                optionsClause = $" with ( {optionsClause} )";
            }

            var includeClause = "";

            if (Include.Count > 0)
            {
                for (var idx = 0; idx < Include.Count; idx++)
                {
                    Include[idx] = $"[{Include[idx]}]";
                }
                includeClause = string.Join(", ", Include.ToArray());
                includeClause = $" include ( {includeClause} )";
            }

            var whereClause = "";

            if (!string.IsNullOrEmpty(Where))
            {
                whereClause = $" where ( {Where} )";
            }

            var onClause = "";

            if (!string.IsNullOrEmpty(On))
            {
                onClause = $" on {On}";
            }

            var fileStreamClause = "";

            if (!string.IsNullOrEmpty(FileStreamOn))
            {
                // ReSharper disable once StringLiteralTypo
                fileStreamClause = $" filestream_on {FileStreamOn}";
            }

            for (var idx = 0; idx < ColumnName.Count; idx++)
            {
                var modifier = "";
                if (idx < Descending.Length && Descending[idx])
                {
                    modifier = " desc";
                }
                ColumnName[idx] = $"[{ColumnName[idx]}]{modifier}";
            }

            var columnClause = string.Join(", ", ColumnName.ToArray());

            var query =
                $"create{uniqueClause}{clusteredClause} index [{Name}] on [{SchemaName}].[{TableName}] ({columnClause}){includeClause}{optionsClause}{whereClause}{onClause}{fileStreamClause}";

            return(query);
        }