sys.foreign_keys fk join sys.foreign_key_columns fkc
on fk.object_id=fkc.constraint_object_id
where fkc.parent_object_id = object_id('%(schema_dot)s%(tname)s')
-`and col_name(fkc.parent_object_id, fkc.parent_column_id) = '%(colname)s'
+and col_name(fkc.parent_object_id, fkc.parent_column_id) = '%(colname)s'
exec('alter table %(tname_quoted)s drop constraint ' + @const_name)""" % {
"tname": tname,
"colname": colname,
--- /dev/null
+.. change::
+ :tags: bug, mssql
+ :tickets: 716
+
+ Fixed issue where the ``mssql_drop_foreign_key=True`` flag on
+ ``op.drop_column`` would lead to incorrect syntax error due to a typo in the
+ SQL emitted, same typo was present in the test as well so it was not
+ detected. Pull request courtesy Oleg Shigorin.
"select @const_name = [name] from\n"
"sys.foreign_keys fk join sys.foreign_key_columns fkcon "
"fk.object_id=fkc.constraint_object_id\n"
- "where fkc.parent_object_id = object_id('t1')`and "
+ "where fkc.parent_object_id = object_id('t1')\nand "
"col_name(fkc.parent_object_id, fkc.parent_column_id) = 'c1'\n"
"exec('alter table t1 drop constraint ' + @const_name)"
)
"select @const_name = [name] from\n"
"sys.foreign_keys fk join sys.foreign_key_columns fkcon "
"fk.object_id=fkc.constraint_object_id\n"
- "where fkc.parent_object_id = object_id('xyz.t1')`and "
+ "where fkc.parent_object_id = object_id('xyz.t1')\nand "
"col_name(fkc.parent_object_id, fkc.parent_column_id) = 'c1'\n"
"exec('alter table xyz.t1 drop constraint ' + @const_name)"
)