SQL仅在数据库中存在该表的情况下才更新该表 [英] SQL to update a table only if that table exists in the database

查看:61
本文介绍了SQL仅在数据库中存在该表的情况下才更新该表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mySQL数据库,该数据库可能有一个名为jason的表. 数据库的一个单独实例可能没有jason表(它将具有其他共同的表)

I have a mySQL database that might have a table named jason. A separate instance of the database may not have the jason table (it would have other tables in common)

我想针对两个数据库运行一个简单的更新,但是该更新是针对jason表的.

I'd like to run a simple update against both databases but the update is for the jason table.

我知道我可以做类似的事情

I know I can do something like

DROP TABLE IF EXISTS `jason`;

是否可以运行类似以下内容的更新:

Is it possible to run an Update something like:

IF EXISTS `jason` UPDATE `jason` SET...

我似乎什么也没用.

推荐答案

只需运行update语句,如果该表不存在,它将失败并且不会造成损坏.

Just run the update statement, if the table didn't exist, it will fail and cause no damage.

这篇关于SQL仅在数据库中存在该表的情况下才更新该表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆