Table of Contents
替换SQL Server数据库中所有表的所有字段的某些内容
Home Database Mysql Tutorial 替换SQL Server数据库中所有表的所有字段的某些内容--方法二

替换SQL Server数据库中所有表的所有字段的某些内容--方法二

Jun 07, 2016 pm 02:54 PM
server sql content Field database replace

替换SQL Server数据库中所有表的所有字段的某些内容 替换 表字段 内容 declare @t varchar(255),@c varchar(255) declare table_cursor cursor for select a.name,b.name from sysobjects a,syscolumns b ,systypes c where a.id=b.id and a.xtype='u' and c

替换SQL Server数据库中所有表的所有字段的某些内容

替换 表字段 内容
declare @t varchar(255),@c varchar(255) 
declare table_cursor cursor for 
select a.name,b.name from sysobjects a,syscolumns b ,systypes c 
where a.id=b.id and a.xtype='u' and c.name in (--这里是要替换的类型 
'char', 'nchar', 'nvarchar', 'varchar','text','ntext' --这里如果你的text(ntext)类型没有超过8000(4000)长度,才可以使用
) 
declare @str varchar(500),@str2 varchar(500) 
--这里是你要替换的原字符 
set @str='aa' 
--这里是你要替换的新字符 
set @str2='bb'
open table_cursor fetch next from table_cursor into @t,@c 
while(@@fetch_status=0) 
begin 
    exec('update [' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''+ @str2 +''')') 
    fetch next from table_cursor into @t,@c 
end 
close table_cursor 
deallocate table_cursor;
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

What is the difference between HQL and SQL in Hibernate framework?

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

How does Go language implement the addition, deletion, modification and query operations of the database?

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

How does Hibernate implement polymorphic mapping?

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

An in-depth analysis of how HTML reads the database

PHP replacement skills revealed! PHP replacement skills revealed! Mar 28, 2024 am 08:57 AM

PHP replacement skills revealed!

Tips and practices for handling Chinese garbled characters in databases with PHP Tips and practices for handling Chinese garbled characters in databases with PHP Mar 27, 2024 pm 05:21 PM

Tips and practices for handling Chinese garbled characters in databases with PHP

See all articles