Mar
12

find//replace

Uncategorized

I messed up my SQL tables just now, luckily I did back up before I play with these things. What I was trying to do is to be neater. I don’t want a link to point at some empty location in my blog.

What I did is to do a replacement in certain fields to update blog.beconfused.com into beconfused.com or beconfused.com/blog

That really messed my tables up because my MySQL knowledge sucks. I come from a Microsoft SQL (MSSQL) background. Not that I am an expert in MSSQL, I think I got a B for that module and I remember Yong Liang got an A or probably a distinction. MSSQL is like Yong Liang’s forté.

UPDATE `NameOfTable` SET `NameOfAttribute`= replace(`NameOfAttribute`, "ReplaceFromString", "ReplaceToString")

Well, the syntax looks something like this. What it is trying to do is to UPDATE the field `NameOfAttribute` in the table `NameOfTable`. Then there is this nice little function called ‘replace‘ where you can replace any part of the string from `ReplaceFromString` to `ReplaceToString`.

An example would be:

UPDATE `wp_posts` SET `post_content` = replace(`post_content`, "http://blog.beconfused.com/archives/", "http://beconfused.com/blog/")

What this code is doing is to perform a find and replace. It targets the text “http://blog.beconfused.com/archives/” and changes it into “http://beconfused.com/blog/”. It searches in the field `post_content` under the table `wp_posts`.

What’s left is just my upgrade to WordPress 1.5. :)

Tags:

4 comments for “find//replace”

  1. Yeah, I know what you mean. I have learned SQL myself, was part of my education, but never used it since 2 years. I doubt I am a good SQL coder nowadays.

    by Nafcom (Mar 13, 2005 at 1 AM)
  2. Nafcom: Yeah, my girlfriend and I wishes there would be an undo feature in SQL, lol..

    Well, you just have to back up everything before you play with it I suppose.

    by Mr. Dew (Mar 13, 2005 at 10 PM)
  3. Mr. Dew: No I rather think, I would have need to start from zero learning SQL again :D

    by Nafcom (Mar 14, 2005 at 7 AM)
  4. Yeah, that’s true, hahaa..

    by Mr. Dew (Mar 14, 2005 at 7 AM)
 

Leave a Reply

 

Comments may be moderated due to spam. No advertisements are allowed in comments.

You'll require some math knowledge to comment, this is done to stop evil bots from spamming my blog.

Read my comments policy

Want a display picture?