zoukankan      html  css  js  c++  java
  • SQLServer查询所有表所有字段包含xx的信息

    从系统表自动生成sql语句来运行得到结果

    select a.name as columnname,object_name(a.id)as tablename into t from syscolumns a,

    sysobjects b,

    systypes c

    where a.id=b.id  

    and a.xtype=c.xtype

    and b.xtype='u'

    and c.name in('varchar','nvarchar','char','nchar','text','ntext')

    and object_name(a.id)<>'t'

     

    go

     

    create function udf_genSQL(@tableName varchar(1000),@keyword varchar(1000))

    returns varchar(8000)

    as

    begin

        declare @sql varchar(8000)

        set @sql='select * from '+@tableName +' where 1=1 '

        select @sql=@sql+' or '+

           columnname +' like ''%'+@keyword+'%''' from t

        where tablename=@tablename

        return @sql

    end

    go

     

    select dbo.udf_genSQL(tableName,'a') from t group by tablename

     

    drop table t

    drop function dbo.udf_genSQL

     

     

     

     


  • 相关阅读:
    httpd sshd firewalld 服务后面的d的意思
    js parse_url 引发的
    python的shutil模块
    ubuntu18.04 LTS上安装并使用nvm管理node版本
    【ZIP】打包过滤指定目录和文件
    numpy中的reshape中参数为-1
    机器学习python常用模块
    Python3使运行暂停的方法
    thrift
    一个账号只能在一处登陆,不是单点登陆。
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6204872.html
Copyright © 2011-2022 走看看