WEB开发网
开发学院数据库MSSQL Server 在 SQL Server 2005 中查询表结构及索引 阅读

在 SQL Server 2005 中查询表结构及索引

 2007-05-13 09:26:08 来源:WEB开发网   
核心提示: 索引及主键信息--邹建2005.08(引用请保留此信息)--SELECT TableId=O.[object_id], TableName=O.Name, IndexId=ISNULL(KC.[object_id],IDX.index_id), IndexName=IDX.Name, In

--========================================================================

--索引及主键信息

--邹建2005.08(引用请保留此信息)

--========================================================================

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=CASEINDEXKEY_PROPERTY(IDXC.[object_id],IDXC.index_id,IDXC.index_column_id,'IsDescending')
     WHEN1THEN'DESC'WHEN0THEN'ASC'ELSE''END,
   PrimaryKey=CASEWHENIDX.is_primary_key=1THENN'√'ELSEN''END,
   [UQIQUE]=CASEWHENIDX.is_unique=1THENN'√'ELSEN''END,
   Ignore_dup_key=CASEWHENIDX.ignore_dup_key=1THENN'√'ELSEN''END,
   Disabled=CASEWHENIDX.is_disabled=1THENN'√'ELSEN''END,
   Fill_factor=IDX.fill_factor,
   Padded=CASEWHENIDX.is_padded=1THENN'√'ELSEN''END
FROMsys.indexesIDX
   INNERJOINsys.index_columnsIDXC
     ONIDX.[object_id]=IDXC.[object_id]
       ANDIDX.index_id=IDXC.index_id
   LEFTJOINsys.key_constraintsKC
     ONIDX.[object_id]=KC.[parent_object_id]
       ANDIDX.index_id=KC.unique_index_id
   INNERJOINsys.objectsO
     ONO.[object_id]=IDX.[object_id]
   INNERJOINsys.columnsC
     ONO.[object_id]=C.[object_id]
       ANDO.type='U'
       ANDO.is_ms_shipped=0
       ANDIDXC.Column_id=C.Column_id
--  INNERJOIN --对于一个列包含多个索引的情况,只显示第1个索引信息
--  (
--    SELECT[object_id],Column_id,index_id=MIN(index_id)
--    FROMsys.index_columns
--    GROUPBY[object_id],Column_id
--  )IDXCUQ
--    ONIDXC.[object_id]=IDXCUQ.[object_id]
--      ANDIDXC.Column_id=IDXCUQ.Column_id
--   

上一页  1 2 

Tags:SQL Server 查询表

编辑录入:coldstar [复制链接] [打 印]
赞助商链接