Drop constraints only if it exists in mysql server 5.0

允我心安 提交于 2019-12-10 17:00:24

问题


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



来源:https://stackoverflow.com/questions/544825/drop-constraints-only-if-it-exists-in-mysql-server-5-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!