仅当它存在于mysql服务器5.0中时,删除约束 [英] Drop constraints only if it exists in mysql server 5.0
问题描述
我想知道仅在存在约束的情况下如何删除它. mysql服务器中是否存在任何单行语句,这将允许我执行此操作.
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;
对此的任何帮助确实帮助我在mysql中前进
any help to this really help me to go forward in mysql
推荐答案
除非您愿意检测错误并继续操作(而不是不好的事情.)
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).
INFORMATION_SCHEMA数据库包含您需要告知外键是否存在的信息,因此您可以分两步实施.
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
这篇关于仅当它存在于mysql服务器5.0中时,删除约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!