Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011

    Unanswered: difference between replace and update

    May I know the difference between replace and update?

  2. #2
    Join Date
    Sep 2009
    San Sebastian, Spain
    The replace is a string function used in MySQL. The UPDATE is a command telling the database what to do. So for example if you want to perform changes in a database table you would use:

    UPDATE table SET field = newvalue;

    On the other hand REPLACE is a function which can be used to replace one string with another and return the new string.

    SELECT REPLACE(field, oldstring, newstring) FROM table;

    The SELECT statement uses REPLACE to display a new string replacing occurrences of old string in the column "field". You can use UPDATE and REPLACE together, for example imagine a table contains a field which has data that needs to be modified, imagine it contains the string "Field: data" and we want to strip off "Field: " resulting in only the data we would issue something like:

    UPDATE table SET field = REPLACE(field, "Field: ", "");
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    Follow me on Twitter

  3. #3
    Join Date
    Apr 2002
    Toronto, Canada
    REPLACE is not only a function, it's also a (non-standard) statement
    Quote Originally Posted by da manual
    REPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record for a PRIMARY KEY or a UNIQUE index, the old record is deleted before the new record is inserted. | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts