t-sql 查找一个数据库下所有表下字段类型为GUID且索引为聚集索引的主键

select  TableId = O.[object_id],
TableName = O.Name,
IndexId = isnull(KC.[object_id],IDX.index_id),
IndexName = IDX.Name,
IndexType = isnull(KC.type_desc,'Index'),
Index_Column_id = IDXC.index_column_id,
ColumnID = C.Column_id,
ColumnName = C.Name,
Sort = case indexkey_property(IDXC.[object_id],IDXC.index_id,
IDXC.index_column_id,'IsDescending')
when 1 then 'DESC'
when 0 then 'ASC'
else ''
end,
PrimaryKey = case when IDX.is_primary_key=1 then N''
else N''
end,
[UQIQUE] = case when IDX.is_unique=1 then N''
else N''
end,
Ignore_dup_key = case when IDX.ignore_dup_key=1 then N''
else N''
end,
Disabled = case when IDX.is_disabled=1 then N''
else N''
end,
Fill_factor = IDX.fill_factor,
Padded = case when IDX.is_padded=1 then N''
else N''
end,
T.name,IDX.type_desc
from sys.indexes IDX
inner join sys.index_columns IDXC
on IDX.[object_id]=IDXC.[object_id]
and IDX.index_id=IDXC.index_id
left join sys.key_constraints KC
on IDX.[object_id]=KC.[parent_object_id]
and IDX.index_id=KC.unique_index_id
inner join sys.objects O
on O.[object_id]=IDX.[object_id]
inner join sys.columns C
on O.[object_id]=C.[object_id]
and O.type='U'
and O.is_ms_shipped=0
and IDXC.Column_id=C.Column_id
left join sys.types T on C.system_type_id=T.system_type_id
where IDX.is_primary_key=1 and IDX.type_desc='CLUSTERED'
and T.name='uniqueidentifier'

转载于:https://www.cnblogs.com/Bodil/archive/2011/11/23/all-clustered-index-primarykey-in-a-database.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值