Drop constraints only if it exists in mysql server

2019-06-24 04:31发布

问题:

i want to know how to drop a constraint only if it exists. is there any single line statement present in mysql server which will allow me to do this.

i have tried the following command but unable to get the desire output

alter table airlines 
drop foreign key if exits FK_airlines;

any help to this really help me to go forward in mysql

回答1:

I do not believe this is possible in a single line, unless you are willing to detect the error and move on (not a bad thing).

The INFORMATION_SCHEMA database contains the info you need to tell if the foreign key exists, so you could implement it in a 2 step process.

http://dev.mysql.com/doc/refman/5.1/en/table-constraints-table.html



回答2:

yep not possible the if exist is available only for database table and view : http://dev.mysql.com/doc/refman/5.0/en/replication-features-drop-if-exists.html

yep 2 step process is a good way like gahooa said



标签: mysql4