How to search and replace part of a row in all columns in all tables in sql database

Is it possible to search and replace all occurrences of a row in all columns in all database tables? I am using Microsoft SQL Server.

+3
source share
3 answers

Not easy, although I can do two ways to do this:

  • Write down a series of stored procedures that identify all the varchar and text columns of all tables and generate separate update statements for each column of each table in the form "UPDATE foo SET BAR = REPLACE (BAR," foobar "," quux ")"). Probably this is due to a large number of queries to system tables with a large number of experiments - Microsoft is not going to document this material.
  • , /, . , MS SQL Server, . Microsoft Microsoft SQL Server Database Publishing Wizard , SQL Server , SQL DDL DML. , , sqlcmd, .

, , DPW SQL Server. , , (MS SQL Server 2000/2005), .

+4

MySQL :

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

.

Example:
update users set vct_filesneeded = replace(vct_filesneeded,'.avi','.ai');

: http://www.mediacollege.com/computer/database/mysql/find-replace.html

+2

A good starting point for writing such a query is the “Search all columns in all tables in a database for a specific value” procedure. The full code is on the link (not trivial, but copy / paste it and use it, it just works).

From there, it is relatively trivial to make changes to the code to replace the values ​​found.

+1
source

Source: https://habr.com/ru/post/1749567/


All Articles