Unanswered: Trying to script the dropping of a constraint in our build
We have an automated build process that applies DDL patches to various instances of our schema.
Someone introduced a table with a foreign key constraint that was not named and was propogated to several database instances. Now, we need to drop that constraint but can not since each MSSQL has named it differently.
I was hoping to troll through the system catelog to get the name and the drop it. While I can find the name, the ALTER statement does not seem to like declared @variables.
Here is my script:
declare @fkname char(64)
@fkname = fk.name
t.name = 'entity_member' and
c.id = t.id and
f.constid = c.constid and
fk.id = c.constid and
fk.xtype = 'F' and
rt.id = f.rkeyid and
rt.name = 'community'
ALTER TABLE entity_member DROP CONSTRAINT @fkname