MySQL Forums
Forum List  »  InnoDB

Re: Drop foreign key only if it exists
Posted by: William Chiquito
Date: July 17, 2008 08:21PM

Hi Eugene,

Try:
DELIMITER $$

DROP PROCEDURE IF EXISTS `DropFK`$$

CREATE PROCEDURE `DropFK`()
BEGIN
IF EXISTS (SELECT NULL FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = DATABASE() AND CONSTRAINT_NAME = 'object_ibfk_1') THEN
	ALTER TABLE `object` DROP FOREIGN KEY `object_ibfk_1`; 
END IF;
END$$

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Drop foreign key only if it exists
13773
July 17, 2008 08:21PM
19246
February 11, 2009 01:32PM
12917
February 12, 2009 10:47AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.