查询数据库中某个特定的字段所在的所以表(不包含视图)

 

--查询数据库中某个特定的字段所在的所以表(不包含视图)

select a.[name] 表名 from sysobjects a
left join(select [id],count(*) b from syscolumns where [name]
in('Id','SellerNick') group by [id] having count(*)>1
) b on a.[id]=b.[id]
where b.id is not null  and a.type<>'V'

 

 

--创建虚拟表,把值带给他
declare @tb table(NewSellerNick nvarchar(20),SellerNick nvarchar(20))
insert @tb
select '演示店铺'+CAST(id as nvarchar(10)),SellerNick from T_ERP_Shop

 

----查询数据库中某个特定的字段所在的所以表(不包含视图)并修改这些表的指定字段的内容

 
select 'update '+ a.[name]+' set SellerNick=t.NewSellerNick from @tb t where t.SellerNick='+ a.[name]+'.SellerNick' 表名 from sysobjects a

left join(select [id],count(*) b from syscolumns where [name]
in('Id','SellerNick') group by [id] having count(*)>1
) b on a.[id]=b.[id]
where b.id is not null  and a.type<>'V'

 

 

 

 

posted on 2014-02-28 11:07  仅此一个年华  阅读(378)  评论(0)    收藏  举报

导航