首页 > 其他 > 详细

查询当前库中包含某个字段并且包含自增的表

时间:2017-03-15 12:41:16      阅读:173      评论:0      收藏:0      [点我收藏+]

查询当前库中包含某个字段并且包含自增的表

-- use dbname
--当前库中包含某个字段的表
select top 1000 o.name as tablename,c.name as colname 
from dbo.syscolumns c join sysobjects o on c.id=o.id 
--and uid= USER_ID(dbo)
where 1=1
and c.name=col_name
and o.type=U 
order by o.name 


--当前库中包含某个字段and Identity 的表
select top 1000 o.name as tablename,c.name as colname 
from dbo.syscolumns c join sysobjects o on c.id=o.id 
--and uid= USER_ID(dbo)
where 1=1
and c.name=col_name
and o.type=U 
--order by o.name 
and o.name  in (
select tablename from (
select  o.name as tablename,c.name as colname ,c.id,c.name
,CASE WHEN COLUMNPROPERTY(c.id, c.name, IsIdentity) = 1 THEN 
             ELSE ‘‘
        END AS 标识 
from dbo.syscolumns c join sysobjects o on c.id=o.id 
--and uid= USER_ID(dbo)
where 1=1
--and c.name=‘userid‘
and o.type=U 
) t where t.标识=
)
order by o.name 

 

查询当前库中包含某个字段并且包含自增的表

原文:http://www.cnblogs.com/davidhou/p/6553137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!