查询所有表中所有字段

求一SQL语句,查询一个库中所有表中所有字段,只要符合关键字,就输出。
比如有三个表1(a,b),2(c),3(d,e,f)。
在这三个表中搜索等于word的数据。
1,2,3是我的假设
如果库中有1000个表我不能全给打出来吧,还有字段名也不需要,就是查询这个库中所有数据等于word的数据.

4楼的大哥,希望你给各详解。
最新回答
没什么大不了

2026-10-31 12:25:05

用循环慢慢写:
获取所有表名:
select name from sysobjects where type='U'

获取所有字段名:
Select Name from SysColumns Where id=Object_Id('TableName')
我想你会懂

2026-01-06 11:12:46

只有用动态sql 来做,最好结合存贮过程

关于表,字段的信息都可以从系统的一些表来取得
比如sql server -> systables , syscolumns
其他也大致一样。

第一层游标循环 -> 表
第二层游标循环 -> 字段

拼出动态sql => select *
from table_name
where field1 like '%keyword%'
or field2 like '%keyword%'
or field3 like '%keyword%'
...

插入临时表

循环完毕
取得所有的结果。
二到无穷大

2026-05-14 21:16:27

select a from 1 where a='word'
union all
select b from 1 where b='word'
union all
select c from 2 where c='word'
union all
select d from 3 where d='word'
union all
select e from 3 where e='word'
union all
select f from 3 where f='word'
听一首歌流一夜泪

2026-01-26 05:54:15

是在不知道你要怎么省略
select * from 表名 where 字段=“word”
我觉得只能这样了,不管是10个表还是100个表,查询语句只能这样写吧,呵呵,不过我还是个新手,要有好的办法也未尝可知,希望有帮助
战皆罪

2026-07-18 15:34:02

select * from 1,2,3 where 字段=关键字