Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 01-25-2007, 11:55 AM Parse the Data
Junior Talker

Posts: 4
Name: Bob Williams
Trades: 0
Have a MYSQL database. Anyone know how to go through all the data fields in the database looking for a certain character, such as a ";" and replace it with a blank and then put it back into the database?
bobwill is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-25-2007, 06:46 PM Re: Parse the Data
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
UPDATE table SET column = REPLACE(column,";"," ")
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-26-2007, 12:56 AM Re: Parse the Data
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Quote:
Originally Posted by chrishirst View Post
UPDATE table SET column = REPLACE(column,";"," ")
Ah, but how do you know which table and which column?

In SQL Server ( Microsoft ), you can use one query ( Select name From sysObjects Where xType = 'u' -- u as in user table ) to get a list of all the tables in the database, and another ( Select name From sysColumns ) to get a list of columns. You would do this as an iteration: for each row in sysObjects, you also want it's ID, and use that in the where clause against sysColumns to get the columns for that particular table. And for each of those, you would fire off the above update query. Which means potentially thousands of update commands.

No idea how this would be accomplished in MySql, but I'm guessing it's similarly easy.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 01-26-2007, 05:55 AM Re: Parse the Data
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Quote:
Originally Posted by ForrestCroce View Post
Ah, but how do you know which table and which column?
In the query "UPDATE table SET column = REPLACE(column, ";"," ")"
table is the name of the table you want to update and column is the name of the column in that table. Let's say I had a table called users and wanted to change entries in the column called address, the query would be: -

UPDATE users SET address = REPLACE(address, ";", " ")

Moving on, it is just as easy (if not easier) to get a list of tables from a given database with the following query:

SHOW TABLES FROM db_name;

and a list of columns from a given table:

SHOW COLUMNS FROM tbl_name;

Likewise, one could iterate throughout and perform multiple updates if required

Hope this adds something for someone
Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Parse the Data
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.65155 seconds with 12 queries