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

     

     

     

     


  • 相关阅读:
    HDU 4278 Faulty Odometer 8进制转10进制
    hdu 4740 The Donkey of Gui Zhou bfs
    hdu 4739 Zhuge Liang's Mines 随机化
    hdu 4738 Caocao's Bridges tarjan
    Codeforces Gym 100187M M. Heaviside Function two pointer
    codeforces Gym 100187L L. Ministry of Truth 水题
    Codeforces Gym 100187K K. Perpetuum Mobile 构造
    codeforces Gym 100187J J. Deck Shuffling dfs
    codeforces Gym 100187H H. Mysterious Photos 水题
    windows服务名称不是单个单词的如何启动?
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6204872.html
Copyright © 2011-2022 走看看