sql update replace

Category: Databases

False007
Asked:
2013-03-20 2:05 am EST

Hits: 371
I need to replace all instances of http://oldwebsite with http://newwebsite with out removing other content in Column.

Where can I get me some cookies?&nbsp; <img alt="surprise" height="20" src="http://oldwebsite/plugin/wysiwyg-editor/plugins/smiley/images/omg_smile.gif" title="surprise" width="20"></p>

Need it to be changed to.

Where can I get me some cookies?&nbsp; <img alt="surprise" height="20" src="http://newwebsite/plugin/wysiwyg-editor/plugins/smiley/images/omg_smile.gif" title="surprise" width="20"></p>

Will the update replace do this without removing every thing else.

UPDATE posts SET content = replace(content, 'http://oldwebsite/da/', 'http://newwebsite/da/' ) ;

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

BradM
Staff
5,399 Points
2013-03-20 2:13 am EST
Hi False007,

The syntax for you Update query looks correct at first look. As long as the information you want to change is in the posts table and specifically in the content column, you should be OK.

To be on the safe side however, but sure to generate a backup of your database before running a command like this.

I hope that helps! Let us know if we can help any further.

Thanks,
- Brad

You must login before you can post a comment about this answer.

Thank you for the quick answer Brad.
False007
22 Points
2013-03-20 2:43 am EST
0

jamesr
Staff
5,889 Points
2013-03-20 2:18 am EST
Thank you for your question False007!

You can run an SQL statement; however, this will change your live database. If the SQL statement goes wrong for any reason, your live copy can be damaged.

You can export your database as an SQL file to your local computer. Make a copy of it, then use find and replace in a text editor like Notepad++ to find and replace all instances of the old domain with the new domain. After you get the backup copy updated you can Import the database on your server. This way you can prevent any problems that may arise when changing the URL and keep a back up of the database.

Best Regards,
James R

You must login before you can post a comment about this answer.

Makes good sence, not run a SQL statement on a live database. Thank you for the wize advice.
False007
22 Points
2013-03-20 2:47 am EST
Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!