473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Updating a specific column ( Special case )

539 512MB
I have a table, where it composed of several columns, but i am concerning only on a specific column with datatype varchar under that db table...

Now, for example:

column: links
values:

http://localhost/asdf/asdf.php
http://localhost/
http://localhost/12312/adfdf.php
http://localhost/ghierew/adfd.html


Now, i would like to update the said column such that it only replace the
'http://localhost/' to some value or let us say an existing website rootlink 'http://www.google.com.ph/'

that will result into

http://www.google.com.ph/asdf/asdf.php
http://www.google.com.ph/
http://www.google.com.ph/12312/adfdf.php
http://www.google.com.ph/ghierew/adfd.html

I expect from this db table to have millions of row, therefore i doubt to implement my idea of replacing them one by one at a time because this db table is just acting like a temporary storage that will be truncated by the time the control system will demand a new temporary storage... and it takes little time to process... Thread-timing bug will arise

I believe that the MySQL Server will process this just in time.

Is it possible to do it on just a query? or queries? Java is the front-end
Dec 28 '09 #1

✓ answered by Atli

Hey.

The query to update a table in such a way is simple enough:
Expand|Select|Wrap|Line Numbers
  1. UPDATE `tbl`
  2. SET `links` = REPLACE(`links`, 'http://localhost/', 'http://www.google.com.ph/');
I'm not sure how that will work with you temporary truncation scenario, but if your table gets truncated/re-created often, and you need this to happen for every row that get's inserted, you could try creating a Trigger that does this automatically each time a INSERT statement is issued.
Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER `tbl_links_insert` BEFORE INSERT ON `tbl`
  2. FOR EACH ROW
  3. BEGIN
  4.     NEW.links = REPLACE(NEW.links, 'http://localhost/', 'http://www.google.com.ph/');
  5. END;
This could create a performance bottle-neck though, so you should look out for that.

2 2152
Atli
5,058 Expert 4TB
Hey.

The query to update a table in such a way is simple enough:
Expand|Select|Wrap|Line Numbers
  1. UPDATE `tbl`
  2. SET `links` = REPLACE(`links`, 'http://localhost/', 'http://www.google.com.ph/');
I'm not sure how that will work with you temporary truncation scenario, but if your table gets truncated/re-created often, and you need this to happen for every row that get's inserted, you could try creating a Trigger that does this automatically each time a INSERT statement is issued.
Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER `tbl_links_insert` BEFORE INSERT ON `tbl`
  2. FOR EACH ROW
  3. BEGIN
  4.     NEW.links = REPLACE(NEW.links, 'http://localhost/', 'http://www.google.com.ph/');
  5. END;
This could create a performance bottle-neck though, so you should look out for that.
Dec 28 '09 #2
sukatoa
539 512MB
Thank you for your reply Atli :)
Dec 30 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

53
by: Oliver Fromme | last post by:
Hi, I'm trying to write a Python function that parses an expression and builds a function tree from it (recursively). During parsing, lambda functions for the the terms and sub-expressions...
1
by: Yasaswi Pulavarti | last post by:
Is it possible to order by specific values in a column. For example a column may contain values like N, N1, N2, S, S1, S2, R, T. I want to order by in such a way that all the records with N, N1, or...
1
by: Richard Hollenbeck | last post by:
Hello Newsgroup. You have all been very helpful in the past and I thank you. I try to ask relevant questions so that they don't just benefit me, but also benefit the group. I'm currently...
3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
1
by: BStorm | last post by:
Does anyone know the best way to update a DataTable row column using specific values for a multipart primary key? For example, updating an OrderAmt column in an OrderDetail table where the...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
1
by: sekisho | last post by:
I'm dynamically adding a column of labels and a column of text boxes to a panel on a webform, based on data returned from an SQL query, which the user builds by selecting options from a few...
0
by: astro | last post by:
I have a non-updatable column in a SQL:-Server view that represents a 1-to {0,1} relation with a child table. I want the end-user to be able to change this value. This view is generated with...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.