protected string ParseKey(KeySchema key)
        {
            var stat = new StringBuilder();

            switch (key.KeyType)
            {
            case ConstraintType.KeyForeign:
                stat.AppendFormat(@"FOREIGN KEY ({0}) REFERENCES {1}",
                                  ParseColumnListIndex(key.Columns).JoinStrings(),
                                  MakeDdlElementName(key.RelTable));

                if (!string.IsNullOrEmpty(key.RelColumns))
                {
                    stat.AppendFormat(@" ({0})", ParseColumnListIndex(key.RelColumns).JoinStrings());
                }

                switch (key.DeleteRule)
                {
                case LinkRule.Cascade:
                    stat.Append(@" ON DELETE CASCADE");
                    break;

                case LinkRule.SetNull:
                    stat.Append(@" ON DELETE SET NULL");
                    break;
                }
                switch (key.UpdateRule)
                {
                case LinkRule.Cascade:
                    stat.Append(@" ON UPDATE CASCADE");
                    break;

                case LinkRule.SetNull:
                    stat.Append(@" ON UPDATE SET NULL");
                    break;
                }
                break;

            case ConstraintType.KeyPrimary:
                //TODO проверить на DB отличных от MS SQL
                stat.AppendFormat(@"PRIMARY KEY ({0})", ParseColumnListIndex(key.Columns).JoinStrings(@","));
                break;

            case ConstraintType.Unique:
                stat.AppendFormat(@"UNIQUE ({0})", ParseColumnListIndex(key.Columns).JoinStrings());
                break;

            case ConstraintType.Check:
                stat.AppendFormat(@"CHECK ({0})", key.Source);
                break;

            case ConstraintType.Default:
                stat.AppendFormat(@"DEFAULT {0} FOR {1}", key.Source, key.Columns);
                break;
            }
            return(stat.ToString());
        }
 protected string MakeDdlKeyDrop(KeySchema key, TableSchema table)
 {
     return(string.Format(@"ALTER TABLE {0} DROP CONSTRAINT {1}",
                          MakeDdlElementName(table.Name), MakeDdlElementName(key.Name)));
 }
 protected string MakeDdlDefaultCreate(KeySchema key, TableSchema table)
 {
     return(string.Format(@"ALTER TABLE {0} ADD CONSTRAINT {1} DEFAULT {2} FOR {3}",
                          MakeDdlElementName(table.Name), MakeDdlElementName(key.Name),
                          key.Source, key.Columns));
 }
 protected string MakeDdlKeyCreateByAlter(KeySchema key, TableSchema table)
 {
     return(string.Format(@"ALTER TABLE {0} ADD CONSTRAINT {1} {2}",
                          MakeDdlElementName(table.Name), MakeDdlElementName(key.Name),
                          ParseKey(key)));
 }
 /// <summary>
 /// Проверка необходимости пересоздания связанных Foreign Key
 /// при удаление констрента
 /// </summary>
 /// <param name="eKey"></param>
 /// <returns></returns>
 protected abstract bool CheckKeyTypeForRecreate(KeySchema eKey);