Exemplo n.º 1
0
 /// <summary>
 /// This method generates the SQL to create a new foreign key.
 /// This implementation returns
 /// ALTER TABLE FullyQualifiedTableName ADD CONSTRAINT escapedConstraintName FOREIGN KEY (escapedForeignKeyColumnNames) REFERENCES FullyQualifiedForeignTableName (escapedForeignColumnNames) ON DELETE CASCADE
 /// </summary>
 /// <param name="newForeignKey">Info about the foreign key to create.</param>
 /// <returns>SQL statements to create the foreign key.</returns>
 public virtual IEnumerable <string> CreateForeignKey(ITableSourceForeignKeyInfo newForeignKey)
 {
     yield return(String.Format("ALTER TABLE {0} ADD CONSTRAINT {1} FOREIGN KEY ({2}) REFERENCES {3} ({4}){5}",
                                newForeignKey.TableSource.QualifiedName, Identifiers.EscapeIdentifier(newForeignKey.Name),
                                Identifiers.EscapeIdentifier(newForeignKey.ColumnName), newForeignKey.ReferencedTableSource.QualifiedName,
                                Identifiers.EscapeIdentifier(newForeignKey.ReferencedColumnName), newForeignKey.IsCascadeDelete? " ON DELETE CASCADE": String.Empty));
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method generates the SQL to drop a foreign key previously obtained through the IIntrospectionService API.
        /// This implementation returns "ALTER TABLE FullyQualifiedTableName DROP CONSTRAINT escapedConstraintName"
        /// </summary>
        /// <param name="existingForeignKey">Info about the foreign key to drop.</param>
        /// <returns>SQL statements to drop the foreign key.</returns>
        public virtual IEnumerable <string> DropForeignKey(ITableSourceForeignKeyInfo existingForeignKey)
        {
            string statement = String.Format("ALTER TABLE {0} DROP CONSTRAINT {1}", existingForeignKey.TableSource.QualifiedName,
                                             Identifiers.EscapeIdentifier(existingForeignKey.Name));

            return(statement.ToEnumerable());
        }
Exemplo n.º 3
0
        public override IEnumerable <string> DropForeignKey(ITableSourceForeignKeyInfo existingForeignKey)
        {
            string statement = String.Format("ALTER TABLE {0} DROP FOREIGN KEY {1};", Identifiers.EscapeIdentifier(existingForeignKey.TableSource.Name),
                                             Identifiers.EscapeIdentifier(existingForeignKey.Name));

            return(statement.ToEnumerable());
        }