Difference between revisions of "Find and Replace in SQL database"

From James Dooley's Wiki
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[Category:Knowledge]]
 +
 
If you need to find and replace a small portion of code (such as ~<username> to <url>) in a database you can use something like:
 
If you need to find and replace a small portion of code (such as ~<username> to <url>) in a database you can use something like:
  
<code>
+
<source lang='sql'>
[sql,n]
 
 
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
 
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
 +
</source>
  
 
Just make sure [field_name] is set correctly on both sides. Otherwise you may overwrite data.
 
Just make sure [field_name] is set correctly on both sides. Otherwise you may overwrite data.

Latest revision as of 14:36, 25 March 2014


If you need to find and replace a small portion of code (such as ~<username> to <url>) in a database you can use something like:

update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

Just make sure [field_name] is set correctly on both sides. Otherwise you may overwrite data.