Updating a specific column ( Special case )

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    Updating a specific column ( Special case )

    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:







    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






    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
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    The query to update a table in such a way is simple enough:
    [code=sql]
    UPDATE `tbl`
    SET `links` = REPLACE(`links` , 'http://localhost/', 'http://www.google.com. ph/');[/code]

    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.
    [code=sql]CREATE TRIGGER `tbl_links_inse rt` BEFORE INSERT ON `tbl`
    FOR EACH ROW
    BEGIN
    NEW.links = REPLACE(NEW.lin ks, 'http://localhost/', 'http://www.google.com. ph/');
    END;[/code]
    This could create a performance bottle-neck though, so you should look out for that.

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      Thank you for your reply Atli :)

      Comment

      Working...