日期:2011-01-25 23:11:00 来源:本站整理
<b>教您若何查询SQL索引及主键信息</b>[MSSQL防范]
本文“<b>教您若何查询SQL索引及主键信息</b>[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
SQL索引及主键等信息若何查询是我们都需求知道的知识,下面就教您查询SQL索引及主键信息的办法,但愿对您有所启迪.
- 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,
- CColumnID=C.Column_id,
- CColumnName=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
- 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
- -- INNER JOIN -- 关于一个列包含多个索引的情形,只显示第1个索引信息
- -- (
- -- SELECT [object_id], Column_id, index_id=MIN(index_id)
- -- FROM sys.index_columns
- -- GROUP BY [object_id], Column_id
- -- ) IDXCUQ
- -- ON IDXC.[object_id]=IDXCUQ.[object_id]
- -- AND IDXC.Column_id=IDXCUQ.Column_id
以上就是若何查询SQL索引及主键信息的办法.
<以上是“<b>教您若何查询SQL索引及主键信息</b>[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论