当前位置:首页 » 编程语言 » 批量修改sql文件字符集
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

批量修改sql文件字符集

发布时间: 2022-05-28 12:50:26

‘壹’ sql 批量修改数据

使用update 更新修改数据库数据,更改的结果集是多条数据则为批量修改。
语法格式如:
update 表格 set 列 = 更改值 where 筛选条件
例:
update table set a=1 --将table 中所以a列的值改为 1
update table set a=1 where b=2 --将table 中列b=2的记录中a列的值改为 1

‘贰’ SQL 字段值批量修改

1.筛选?

where
语句
2.同时减去一个固定值
set
列名=列名-固定值
update语句
例如:
表名
table1
字段名
field1
(int)
筛选
>
10
减去一个固定值
-
2
sql语句:
update
table1
set
field1=field1-2
where
field1>10

‘叁’ sql 怎样批量修改字段的首个字符

表为AB,字段为cd
sql语句如下:
update AB set cd = replace(cd,'8K','AK') where cd like '8K%'
如果字段中有可能有多个8K
update AB set cd= case when left(cd,2)='8K' then 'AK'+right(cd,len(cd)-2) else cd end

‘肆’ sql 语句 批量修改

update 表名
set C_METHOD_NAME= lower(substring(REPLACE(C_METHOD_NAME,'process',''),1,1))+
substring(REPLACE(C_METHOD_NAME,'process',''),2,len(REPLACE(C_METHOD_NAME,'process','')))
--REPLACE(C_METHOD_NAME,'process','')用空值取代process
-- lower改小写
--lower(substring(REPLACE(C_METHOD_NAME,'process',''),1,1))把取代后字符串的第一个字母改小写
--再加上后面的字符串

‘伍’ sql怎么批量替换字段里的字符串的

方法一:
varchar和nvarchar类型是支持replace,所以如果你的text不超过8000可以先转换成前面两种类型再使用replace 替换 text ntext 数据类型字段的语句 。

update表名set字段名=replace(cast(与前面一样的字段名asvarchar(8000)),'原本内容','想要替换成什么')

方法二:

update[表名]set字段名=replace(与前面一样的字段名,'原本内容','想要替换成什么')

‘陆’ 怎样用SQL语句批量修改字符串中指定位置的字符

--假如修改第10位的字符
update 表名 set 字段名=left(字段名,9) + '要替换成的内容' + substring(字段名,11,len(字段名))

‘柒’ sql语句进行批量修改

修改语句 update hstlst set h_hmedir='e:\'+SUBSTRING (h_hmedir, 4, len(h_hmedir)-3)where left(h_hmedir,3)='d:\'涉及知识:Update更改表中的现有数据SET指定要更新的列或变量名称的列表SUBSTRING返回字符、binary、text 或 image 表达式的一部分语法SUBSTRING ( expression , start , length )expression是字符串、二进制字符串、text、image、列或包含列的表达式。不要使用包含聚合函数的表达式。start是一个整数,指定子串的开始位置。length是一个整数,指定子串的长度(要返回的字符数或字节数)。LEFT返回从字符串左边开始指定个数的字符。语法LEFT ( character_expression , integer_expression ) 参数character_expression字符或二进制数据表达式。character_expression 可以是常量、变量或列。character_expression 必须是可以隐式地转换为 varchar 的数据类型。否则,请使用 CAST 函数显式转换 character_expression。integer_expression是正整数。如果 integer_expression 为负,则返回空字符串。返回类型varchar爱上网iSuNet论坛谢谢您的支持,转载请带本帖地址:[url]http://www.ningood.com/viewthread.php?tid=5638&fromuid=0[/url]

‘捌’ sql批量修改字段

通过存储过程来实现,方法说明:
1、建一个临时表用于存放表名和字段名;
2、在系统表中查看有该字段的所有表,存入临时表
3、在临时表建游标,逐条执行修改;
4、删除临时表。

CREATE PROCEDURE Rename
@databaseName varchar(500),
@oldName varchar(500),
@newName varchar(500)
AS
create table #temp(tablename varchar(200),columnName varchar(200))
declare @tableName_cursor varchar(200)
declare @colName_cursor varchar(200)
declare @objName varchar(200)
declare @tableName varchar(200),@colName varchar(200)
exec('declare tableName_cursor cursor for select name from '+@databaseName+'.dbo.sysobjects where xtype=''u'' and status >= 0')
open tableName_cursor
fetch next from tableName_cursor into @tableName_cursor
while @@fetch_status = 0
begin
insert into #temp select @tableName_cursor,name from syscolumns where id = object_id(@tableName_cursor)
fetch next from tableName_cursor into @tableName_cursor
end
close tableName_cursor
deallocate tableName_cursor

declare col_cursor cursor for select columnName from #temp
open col_cursor
fetch next from col_cursor into @colName_cursor
while @@fetch_status = 0
begin
if @colName_cursor = @oldName
begin
select @tableName=tableName,@colName=columnName from #temp where columnName = @colName_cursor
set @objName = @tableName+'.'+@colName
exec sp_rename @objName,@newName,'Column'
end
fetch next from col_cursor into @colName_cursor
end
close col_cursor
deallocate col_cursor

select * from #temp where columnName = 'isdeleted' or columnName = 'isdatadeleted'
drop table #temp
GO

exec rename @databaseName='test',@oldName='isdeleted',@newName = 'isdatadeleted'

drop PROCEDURE rename

‘玖’ 关于sql语句如何批量修改数据。

update 分析表 set 调味品='t' where 流水号 in (select 流水号 from 销售表 where 大类名称='调味品')
你字段太多,一句sql只能改一个分类
你就把分类多换几次执行吧

‘拾’ MySQL数据库,如何批量替换整个数据库的个别字符

用phpmyadmin把数据库导出为.sql脚本,空间商一般有提供这个管理工具给用户使用的,如果没提供,你也可以自行上传一个到空间里。用它导出为.sql脚本后,用记事本打开,然后用一次性查找替换,替换之后保存,然后再在phpmyadmin里把原来的表及数据全部删除,删除后重新导入修改好的.sql脚本。

操作以上东西时请先备份你的数据库喔,以免有意想不到的问题发生。