SQL中只知道字段名,要查在哪张表怎么查啊

例数据库为A,字段为B,不知道在哪张表中,要怎么查到它,还要知道它所在的表名啊。

这个每种数据库不一样的
db2中:select TABNAME from syscat.columns where tabschema='x' and colname='字段名'
这里,x指的是db2的模式。
mysql中:select TABLE_NAME from information_schema.columns where table_schema='y' and column_name='字段名'
这里y指的是数据库的名称。
其他数据库应该也会有个系统表存放这些信息,表名以及这些字段的含义都是可以见面知义的,按着这个思路相信你能找到
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-06
select a.Name from (Select Object_Id(Name)as id,Name FROM SysObjects Where XType='U') as a,SysColumns where a.id=SysColumns.id and SysColumns.Name=字段名这样就行了~本回答被网友采纳
第2个回答  2013-09-06
挺难的,我也没想到怎么做,表可以不同,但是里面的字段可以是相同的。
相似回答