在 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
--
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接