If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > difference between replace and update

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-11, 00:24
raindropz raindropz is offline
Registered User
 
Join Date: Apr 2011
Posts: 14
difference between replace and update

May I know the difference between replace and update?
thanks.
Reply With Quote
  #2 (permalink)  
Old 04-30-11, 05:02
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 04-30-11, 05:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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.
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On