sqlserver中查询库中所有字段中带XX信息的表名

linxuanyuzhu 2013-05-23 05:21:24
sqlserver中查询库中所有字段中带XX信息的表名,尽量通过纯sql语句搞定,尽量不用存储过程
...全文
1044 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
铁歌 2013-05-26
  • 打赏
  • 举报
回复
楼上的使用like当然可以但数据量超大的情况下,性能可能会存在问题,可以考虑建立全文索引,然后使用contains关键字查询。
中关村网名 2013-05-23
  • 打赏
  • 举报
回复
Select tb.name as tbname
From sys.columns as  col
Inner Join sys.tables as tb
On col.object_id = tb.object_id
	And col.name like '%sname%'
查询某个数据库。
daiyueqiang2045 2013-05-23
  • 打赏
  • 举报
回复
http://www.cnblogs.com/worfdream/articles/3071705.html
  • 打赏
  • 举报
回复
引用 6 楼 sc273607742 的回复:
select * from sys.columns name like '%XX信息%'
SELECT OBJECT_NAME([object_id]) AS tb_name, name AS column_name FROM sys.columns WHERE name LIKE '%xx%'
sql_sf 2013-05-23
  • 打赏
  • 举报
回复
引用 4 楼 linxuanyuzhu 的回复:
引用 1 楼 sc273607742 的回复:
select * from sys.tables where name like '%XX信息%'
你这样只是把表名带XX的查出来了,不是我想要的,我想要的是库中所有的字段里带有XX信息的表。
sys.columns
哥眼神纯洁不 2013-05-23
  • 打赏
  • 举报
回复
select * from sys.columns name like '%XX信息%'
發糞塗牆 2013-05-23
  • 打赏
  • 举报
回复
查找某数据库中的列是否存在某个值
alter proc spFind_Column_In_DB 
( 
    @type int,--类型:1为文字类型、2为数值类型 
    @str nvarchar(100)--需要搜索的名字 
) 
as
    --创建临时表存放结果 
    create table #tbl(PK int identity primary key ,tbl sysname,col sysname) 
    declare @tbl nvarchar(300),@col sysname,@sql nvarchar(1000) 
    if @type=1  
    begin
        declare curTable cursor fast_forward 
        for 
            select '['+SCHEMA_NAME(SCHEMA_ID)+'].['+o.name+']' tableName,'['+c.name+']' columnName from sys.columns c inner join sys.objects o on c.object_id=o.object_id 
            where o.type_desc='user_table' and user_type_id in (167,175,231,239,35,99) 
    end
    else
    begin 
        declare curTable cursor fast_forward 
        for 
        select '['+SCHEMA_NAME(SCHEMA_ID)+'].['+o.name+']' tableName,'['+c.name+']' columnName from sys.columns c inner join sys.objects o on c.object_id=o.object_id 
            where o.type_desc='user_table' and user_type_id in (56,48,52,59,60,62,106,108,122) 
    end
    open curtable 
    fetch next from curtable into @tbl,@col 
    while @@FETCH_STATUS=0 
    begin
        set @sql='if exists (select * from '+@tbl+' where '
        if @type=1 
        begin
            set @sql += @col + ' like ''%'+@str +'%'')'
        end
        else 
        begin
            set @sql +=@col + ' in ('+@str+'))'
        end
  
        set @sql += ' INSERT #TBL(tbl,col) VALUES('''+@tbl+''','''+@col+''')'
        --print @sql 
        exec (@sql) 
        fetch next from curtable into @tbl,@col 
    end
    close curtable  
    deallocate curtable 
    select * from #tbl
linxuanyuzhu 2013-05-23
  • 打赏
  • 举报
回复
引用 1 楼 sc273607742 的回复:
select * from sys.tables where name like '%XX信息%'
你这样只是把表名带XX的查出来了,不是我想要的,我想要的是库中所有的字段里带有XX信息的表。
sql_sf 2013-05-23
  • 打赏
  • 举报
回复
sys.columns --可以看到字段信息 sys.extended_properties --可以看到字段描述信息
黄_瓜 2013-05-23
  • 打赏
  • 举报
回复
什么才叫纯sql? 这个需要定义一些变量的去做的,原理就是去遍历每个对象 对象是从系统表里面获取的。 以前整理过一个,仅供参考 http://blog.csdn.net/beirut/article/details/8244492
哥眼神纯洁不 2013-05-23
  • 打赏
  • 举报
回复
select * from sys.tables where name like '%XX信息%'

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧