当前位置:数据库 > SQLServer >>

谁知道MSSQL 2005查询某个记录所在的表

谁知道MSSQL 2005查询某个记录所在的表的SQL语句怎么写的。 我是菜鸟..希望大鸟们帮帮小弟。 我已经知道该 数据和 数据所对应的字段名称。
答案:declare @lie varchar(50),@shuju varchar(100),@table varchar(50)
select @lie ='列名',@shuju ='数据'
declare @t table (ftable varchar(50))

insert into @t 
select a.name from sys .tables a
left join sys .columns b on a.object_id =b.object_id 
where b.name =@lie

while exists(select 1 from @t)
begin
	select top 1 @table=ftable from @t
	exec('if exists(select 1 from '+@table+' where '+@lie+'='''+@shuju+''') select '''+@table+'''')
	delete from @t where ftable =@table 
end

上一个:mssql 分组查询
下一个:mssql转mysql的问题

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,