# Update all tables in a database?

**URL:** <https://forum.kirupa.com/t/update-all-tables-in-a-database/263393>\
**Category:** programming\
**Created:** [June 15, 2008, 3:44pm UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393 "2008-06-15T15:44:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [June 15, 2008, 3:44pm UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393/1 "2008-06-15T15:44:45Z")

</div>

I want to do something like

```auto

UPDATE * SET fieldName = "value" WHERE fieldName = "oldValue"

```

on an entire database - but that doesnt work - how hard should it be? Anyone know what the correct way to do this is?

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 15, 2008, 3:58pm UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393/2 "2008-06-15T15:58:21Z")

</div>

I might be wrong, but I think an UPDATE statement can only modify data of a single table. It’s quite possible that you can achieve the same effect by literally specifying each table and doing joins, but that seems slightly redundant. I think your only choices are either two update statements or writing a stored procedure.

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [June 15, 2008, 5:52pm UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393/3 "2008-06-15T17:52:43Z")

</div>

■■■■, thats kind of a problem…can anyone else verify there is no way to UPDATE an undetermined amount of tables that may or may not have a column with the right value?

The only other thing I can think is multiple queries - first one a SHOW TABLES that gets the field names and finds any with the relevant field, then for each table that has that field, it does the update…but if theres an easier way?

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 15, 2008, 7:28pm UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393/4 "2008-06-15T19:28:28Z")

</div>

Yes, stored procedures.

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [June 19, 2008, 4:07am UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393/5 "2008-06-19T04:07:35Z")

</div>

Is that what a stored procedure is?

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 19, 2008, 3:55pm UTC](https://forum.kirupa.com/t/update-all-tables-in-a-database/263393/6 "2008-06-19T15:55:53Z")

</div>

a stored procedure is a sql statement that is saved to your server and can be run by scheduling multiple tables/databases

[http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html](http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html)
