1
2
3
4
5
6
7
8
9
-- Drop the constraint if it exists
set @var=if((SELECT true FROM information_schema.TABLE_CONSTRAINTS WHERE
   CONSTRAINT_SCHEMA = DATABASE() AND
   TABLE_NAME        = 'bluebookfacts' AND
   CONSTRAINT_NAME   = 'fk_bb_log_facts' AND
   CONSTRAINT_TYPE   = 'FOREIGN KEY') = true,'ALTER TABLE bluebook DROP FOREIGN KEY fk_bb_log_facts', 'select 1');
prepare stmt from @var;
execute stmt;
deallocate prepare stmt;