如何在包含具有特定值的列的所有表中找到? [英] How to find in all the tables containing columns having particular values?

查看:104
本文介绍了如何在包含具有特定值的列的所有表中找到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目的是从数据库中找到具有特定值的给定列的所有表。
ie
我有Table1,Table2,Table3,Table4,Table5,Table6,Table7等表。

My aim is to find all the table from database having the given column with particular value. i.e. I have tables like Table1,Table2,Table3,Table4,Table5,Table6, Table7 etc.

在这些表中,表具有列名称NameID。现在我想知道列名为'NameID',值为100的表。

In these tables, some of the tables have column name 'NameID'. Now I want to find out the tables which have column name 'NameID' and value is 100.

任何人都能告诉我如何编写SQL Query?

Can any one tell me how to write SQL Query for that?

推荐答案

如果你不能列出表,我怀疑你可以在查询中做。您需要动态创建查询(使用您发现的表,如Paul Alan Taylor所示)。

If you can't list the tables, I doubt you can do it in a query. You'll need to dynamically create a query (using the tables you found like Paul Alan Taylor showed).

尝试调整:

http://ubercode.bleakllc.com/2008/11/find-any-value-in-any-database -column.html

如果您已经知道所有具有该列的表,并且该列表不会更改,则可以做一个简单的查询如

If you already know all the tables that have the column, and that list of tables isn't subject to change, then you can do a simple query like

  Select 'Table1' from table1 where id = 100
  UNION
  Select 'Table2' from table2 where id = 100
  UNION
  ...

将抛出所有的重复,所以如果多行有id 100,你只能得到表一次,如果这不是你想要的UNION ALL。

UNION will throw out all the dupes so if multiple rows have id 100, you only get the table listed once, if that's not what you want UNION ALL.

这篇关于如何在包含具有特定值的列的所有表中找到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆