Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL to update a table only if that table exists in the database

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)

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...

I can't seem to get anything to work.

like image 843
Jason Avatar asked Nov 05 '22 18:11

Jason


1 Answers

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

like image 77
Null303 Avatar answered Nov 15 '22 05:11

Null303