Example #1
0
        public static string CreateAlterTabelPrimaryKeyConstraintDLL(PrimaryKeyClass constraint, eCreateMode cmode)
        {
            var sb = new StringBuilder();

            if (constraint == null)
            {
                return(string.Empty);
            }

            if ((cmode == eCreateMode.drop) || (cmode == eCreateMode.recreate))
            {
                sb.Append(CreateDropPKConstraintDLL(constraint));
                sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}{Environment.NewLine}");
            }

            if ((cmode == eCreateMode.create) || (cmode == eCreateMode.recreate))
            {
                //ALTER TABLE TADRESSEN ADD CONSTRAINT PK_TADRESSEN PRIMARY KEY(TPLZ_ID);
                //ALTER TABLE #REPLACE_TABLE ADD CONSTRAINT #REPLACE_CONSTRAINT PRIMARY KEY(#REPLACE_COLUMNS);";
                string cmd = SQLPatterns.AlterTableAddPK.Replace(SQLPatterns.PrimaryKey, constraint.Name).Replace(SQLPatterns.ColumnKey, MakeConcatedStr(constraint.FieldNames, ",")).Replace(SQLPatterns.TableKey, constraint.TableName);;


                sb.Append(cmd);
                cmd = (!(constraint.Sorting == eSort.ASC))
                    ? $@"){Environment.NewLine}USING {constraint.Sorting} INDEX {constraint.IndexName};{Environment.NewLine}"
                    : $@"){Environment.NewLine}USING INDEX {constraint.IndexName};{Environment.NewLine}";
                sb.Append(cmd);
            }

            return(sb.ToString());
        }
Example #2
0
        private static string CreateDropPKConstraintDLL(PrimaryKeyClass constraint)
        {
            var sb = new StringBuilder();

            if (constraint.TableName != null)
            {
                sb.Append($@"ALTER TABLE {constraint.TableName} DROP CONSTRAINT {constraint.Name};{Environment.NewLine}");
                sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}{Environment.NewLine}");
            }
            return(sb.ToString());
        }