Re: Search/Replace in entire database?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris Payne wrote:
> Hi everyone,
> 
> I am in the middle of creating an editor where you can search and
> replace on an individual column in a single table then I came across
> something I need to be able to do but not sure how.
> 
> Is it posible (And if so please how :-) to search an entire database
> and all tables within a database and do a find/replace on keywords
> without having to specify each table/column within that table?
> 
> The people I am working for have made some big changes and one of them
> is changing the names of one of their products, but this product name
> appears EVERYWHERE in many tables and in lots of different column
> names, and it would save so much time if I could do a single query
> that would just search EVERYTHING within the database.
> 
> Thanks for any advice you can give me.
> 
> Regards
> 
> Chris Payne

Chris,
This is not really a PHP question, is it? More like a question for the support
group that corresponds to your database software...

However, in my experience databases don't allow a cross-table update in a single
query - you won't be able to do it in one query.

You will either have to
1. work out which columns and tables contain the name
2. script a query to make the changes for each separately
3. test it on a backup version of the database
4. fix the bugs
5 run the script on the live database.

OR (possibly)

1. block access to the database (to prevent any changes while you are processing)
2. dump the whole DB to an SQL script
3. do a search and replace on the text of the SQL script
4. Drop the existing data and reload the database from your SQL dump
5. enable access again so that the users can find the (inevitable) mistakes.

These are both pretty time-consuming - sorry!

Then make a business case for the project of normalising the database, at least
with respect to the product names...

-- 
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux