SQL 查询全部替换

标签 sql database

我想修改以下查询:

UPDATE wp_posts
SET post_content =
      REPLACE(post_content, 'http://oldlink.com', 'http://newlink.com');

成为遍历所有表、列和值的东西。与此类似的东西(但这不起作用):

UPDATE * SET *= REPLACE(*, 'http://oldlink.com', 'http://newlink.com'); 

我想将旧链接的每个实例替换为数据库中的新链接。有什么办法吗?

更新

对不起,我忘了说,它是 MySQL。我目前正在查看所有答案,我会回来告诉你什么有效。谢谢大家!

更新 2

大家好(和姑娘们),我决定转储数据库并进行手动搜索和替换(使用 TextWrangler)。由于这不是(目前)大型数据库,因此它可能是最简单的方法。

最佳答案

这是一个在 SQL Server 上运行的程序——您觉得这样的程序对您有用吗?

Search and Replace SQL Server data in all columns, of all tables

Here's a stored procedure named, SearchAndReplace, that searches through all the character columns of all tables in the current database, and replaces the given string with another user provided string.

关于SQL 查询全部替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7402032/

相关文章:

sql - SQuirreL SQL 客户端不显示 Json 数据

sql - 在 Postgres 的 GIN 索引中使用很少的分析器

sql - 对于单个应用程序来说拥有多个 SQL 数据库是一个坏主意吗?

php - 平表到 TreeView

MySQL 查询 UNION 返回修剪后的字符串

mysql - 将表id合并并替换为两个表SQL的字符串

mysql - 项目和类别 (1 :N) How to get number of total and total active items per category in single SQL query?

sql - 如何在 API 的查询字符串中设计通用过滤运算符?

database - 交错表术语

database - 配置 : error: libpq is not installed or libpq is old