如何查找到sql2005数据库各表中包含字段名(xthhdm=A0100101)的表?

来源:百度知道 编辑:UC知道 时间:2024/05/21 06:32:39
如何查找到sql2005数据库各表中包含字段名(xthhdm=A0100101)的表?
用什么命令呀?
select *from where xthhdm=‘A0100101’对吗?
我的意思是:数据库下有很多表,如何知道那些表含有xthhdm字段,并且字段内容=A0100101
不至于让我一个一个的打开看一下吧

用系统存储过程实现,不用单独写.
超过100个结集时用一个表变量或临时表存储

use Test--数据库
exec sp_msforeachtable 'select ''?'' as TabName,* from ? where xthhdm=''A0100101''',@whereand=' and exists(select 1 from syscolumns where ID=o.ID and Name=''xthhdm'')'

1、比如查找数据库中包含列名【xthhdm】的表名
SELECT d.name
FROM syscolumns a left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and a.name='xthhdm'

2、加上数据信息的话,写个通用的存储过程就可以了。
create proc selec_col_data(
@column_name varchar(100),--查询的列名
@date_condition varchar(1000)--列的数据值(该数据位字符型数据)
)as
declare @cursor_sql varchar(4000)--游标变量
declare @tmp_tname varchar(1000)--临时表名变量
declare @strsql Nvarchar(4000)--临时sql变量
declare @sql_where Nvarchar(4000)--临时sql变量
declare @cnt int--结果数据件数变量
--定义游标,查询满足含有[@column_name]要求的表名
set @cursor_sql=&