I use the following:
DECLARE @ConstraintName varchar(255);
SELECT @ConstraintName = CONSTRAINT_NAME
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE
DECLARE @constraintName VARCHAR(50);
DECLARE @runString VARCHAR(2000);
select @constraintName = CONSTRAINT_NAME
from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE TABLE_NAME = 'TheTable' AND COLUMN_NAME = 'TheColumn';
SET @runString = CONCAT('ALTER TABLE TheTable DROP CONSTRAINT ', @constraintName);
PREPARE stmt1 FROM @runString ;
EXECUTE stm1;
DEALLOCATE PREPARE stmt1;
Try this
SELECT CONSTRAINT_NAME INTO @ConstraintName
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE
TABLE_NAME = 'TheTable'
AND COLUMN_NAME = 'TheColumn';
SET @queryStr = CONCAT('alter table TheTable drop constraint ', @ConstraintName);
PREPARE qry from @queryStr;
EXECUTE qry;
For more information: https://dev.mysql.com/doc/refman/5.7/en/execute.html
Try this :
DECLARE @ConstraintName VARCHAR(255);
SELECT CONSTRAINT_NAME
INTO @ConstraintName
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE
TABLE_NAME = 'TheTable'
AND COLUMN_NAME = 'TheColumn';
alter table TheTable drop constraint @ConstraintName;
Or :
DECLARE @ConstraintName VARCHAR(255);
SELECT @ConstraintName:=CONSTRAINT_NAME
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE
TABLE_NAME = 'TheTable'
AND COLUMN_NAME = 'TheColumn';
alter table TheTable drop constraint @ConstraintName;