詳解sqlserver查詢表索引。本站提示廣大學習愛好者:(詳解sqlserver查詢表索引)文章只能為提供參考,不一定能成為您想要的結果。以下是詳解sqlserver查詢表索引正文
SELECT 索引稱號=a.name
,表名=c.name
,索引字段名=d.name
,索引字段地位=d.colid
FROM sysindexes a JOIN sysindexkeys b ON a.id=b.id AND a.indid=b.indid JOIN sysobjects c ON b.id=c.id JOIN syscolumns d ON b.id=d.id AND b.colid=d.colid WHERE a.indid NOT IN(0,255) -- and c.xtype='U' and c.status>0 --查一切用戶表 AND c.name='message' --查指定表 ORDER BY c.name,a.name,d.name
需創立索引 例如:
依據某列斷定能否有反復記載,假如該列為非主鍵,則創立索引
依據常常查詢的列,創立索引
不必創立索引
字段內容年夜部門一樣,例如:男,女
不要給一切的列都創立索引,如許在創立新記載時,增長保護開支時光。
Oracle 查詢用戶表索引
select index_name,index_type,table_name from user_indexes where table_name='表名'
SqlServer查詢一個表上的索引
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 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 where O.name='cz201' --cz201是你要查詢的表
以上內容就是本文全體所述,願望年夜家愛好。