/// <summary>
		/// Generates the SQL string to create the named Foreign Key Constraint in the database.
		/// </summary>
		/// <param name="d">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
		/// <param name="constraintName">The name to use as the identifier of the constraint in the database.</param>
		/// <param name="defaultSchema"></param>
		/// <param name="defaultCatalog"></param>
		/// <returns>
		/// A string that contains the SQL to create the named Foreign Key Constraint.
		/// </returns>
		public override string SqlConstraintString(Dialect.Dialect d, string constraintName, string defaultCatalog, string defaultSchema)
		{
			string[] cols = new string[ColumnSpan];
			string[] refcols = new string[ColumnSpan];
			int i = 0;
			IEnumerable<Column> refiter;
			if (IsReferenceToPrimaryKey)
				refiter = referencedTable.PrimaryKey.ColumnIterator;
			else
				refiter = referencedColumns;
			foreach (Column column in ColumnIterator)
			{
				cols[i] = column.GetQuotedName(d);
				i++;
			}

			i = 0;
			foreach (Column column in refiter)
			{
				refcols[i] = column.GetQuotedName(d);
				i++;
			}
			string result = d.GetAddForeignKeyConstraintString(constraintName, cols, referencedTable.GetQualifiedName(d, defaultCatalog, defaultSchema), refcols, IsReferenceToPrimaryKey);
			return cascadeDeleteEnabled && d.SupportsCascadeDelete ? result + " on delete cascade" : result;
		}
        public virtual Statement[] Render(AddForeignKeyChange change)
        {
            ForeignKeyInfo fk = change.ForeignKey;

            string[] cols    = fk.Columns.ToArray();
            string[] refcols = fk.ReferencedColumns.ToArray();

            string sql = string.Format("alter table {0} {1}",
                                       GetQualifiedName(change.Table),
                                       _dialect.GetAddForeignKeyConstraintString(fk.Name, cols, GetQualifiedName(change.Table.Schema, fk.ReferencedTable), refcols, true));

            return(new Statement[] { new Statement(sql) });
        }
		/// <summary>
		/// Generates the SQL string to create the named Foreign Key Constraint in the database.
		/// </summary>
		/// <param name="d">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
		/// <param name="constraintName">The name to use as the identifier of the constraint in the database.</param>
		/// <param name="defaultSchema"></param>
		/// <returns>
		/// A string that contains the SQL to create the named Foreign Key Constraint.
		/// </returns>
		public override string SqlConstraintString( Dialect.Dialect d, string constraintName, string defaultSchema )
		{
			string[ ] cols = new string[ColumnSpan];
			string[ ] refcols = new string[ColumnSpan];
			int i = 0;

			foreach( Column col in referencedTable.PrimaryKey.ColumnCollection )
			{
				refcols[ i ] = col.GetQuotedName( d );
				i++;
			}

			i = 0;
			foreach( Column col in ColumnCollection )
			{
				cols[ i ] = col.GetQuotedName( d );
				i++;
			}

			return d.GetAddForeignKeyConstraintString( constraintName, cols, referencedTable.GetQualifiedName( d, defaultSchema ), refcols );
		}
        public override void Visit(CreateForeignKeyCommand command)
        {
            if (ExecuteCustomInterpreter(command))
            {
                return;
            }

            var builder = new StringBuilder();

            builder.Append("alter table ")
            .Append(_dialect.QuoteForTableName(PrefixTableName(command.SrcTable)));

            builder.Append(_dialect.GetAddForeignKeyConstraintString(PrefixTableName(command.Name),
                                                                     command.SrcColumns,
                                                                     _dialect.QuoteForTableName(PrefixTableName(command.DestTable)),
                                                                     command.DestColumns,
                                                                     false));

            _sqlStatements.Add(builder.ToString());

            RunPendingStatements();
        }