zoukankan      html  css  js  c++  java
  • 替换一个数据库中的关键字

    declare @SqlStr varchar(8000)
    declare @SQLStrForU varchar(8000)

    declare @TableName varchar(50)
    declare @TableID bigint

    declare @ColumnName varchar(50)


    declare auth_cur cursor for
    select Name,object_id from sys.all_objects where Type='U'
    open auth_cur
    fetch next from auth_cur into @TableName,@TableID
    while (@@fetch_status=0)
    begin
    set @SqlStr='select '
    set @SQLStrForU='update '+@TableName+' set '
    declare auth_cur1 cursor for
    select a.Name from sys.all_columns a join sys.types b
    on a.system_type_id=b.system_type_id
    where a.object_id=@TableID and b.Name in('varchar','char','nvarchar')
    open auth_cur1
    fetch next from auth_cur1 into @ColumnName
    while (@@fetch_status=0)
    begin
    set @SqlStr=@SqlStr+@ColumnName+','
    set @SQLStrForU=@SQLStrForU+@ColumnName+'=replace('+@ColumnName+',''成都市'',''北京市''),'
    fetch next from auth_cur1 into @ColumnName
    end
    close auth_cur1
    deallocate auth_cur1
    set @SqlStr=substring(@SqlStr,1,len(@SqlStr)-1)
    set @SQLStrForU=substring(@SQLStrForU,1,len(@SQLStrForU)-1)

    set @SqlStr=@SqlStr+' from '+@TableName
    print @SQLStrForU

    exec(@SQLStrForU)

    fetch next from auth_cur into @TableName,@TableID
    end
    close auth_cur
    deallocate auth_cur

  • 相关阅读:
    吃货联盟项目
    字串符笔记
    带有参的方法
    js:自动亮起100盏灯
    JS字面量创建方式的优缺点
    为什么说对象字面量赋值比new Object()高效?
    javascript 字面量
    vue学习(一)、Vue.js简介
    Redis(二):c#连接Redis
    Redis(一):centos下安装。
  • 原文地址:https://www.cnblogs.com/xiaoruilin/p/5315144.html
Copyright © 2011-2022 走看看