查看Table的Index

1,查看table中的index的定义

SELECT
    o.object_id,
    o.name,
    i.index_id,
    i.name as index_name,
    i.type_desc as index_type,
    ic.index_column_id,
    c.name AS columnname,
    iif(ic.is_descending_key=1,‘desc‘,‘asc‘) as sort_direction,
    ic.key_ordinal as index_key_ordinal,
    ic.is_included_column,
    i.fill_factor,
    i.is_padded,
    i.has_filter,
    i.filter_definition,
    ic.partition_ordinal
FROM sys.objects o
INNER JOIN sys.indexes i
    ON o.object_id = i.object_id
INNER JOIN sys.index_columns ic
    ON i.object_id = ic.object_id AND i.index_id = ic.index_id
INNER JOIN sys.columns c
    ON o.object_id = c.object_id AND ic.column_id = c.column_id
WHERE o.name = ‘table_name‘
    --and i.name=‘index_name‘
ORDER BY i.index_id,ic.index_column_id

2,查看Index Page占用的物理存储空间

declare @db_id smallint
declare @object_id int
declare @index_id int
declare @Model nvarchar(20)

set @db_id=db_id()
set @object_id=object_id(‘FactThread‘,‘U‘)
set @index_id=null
set @Model=N‘DETAILED‘  --DEFAULT, NULL, LIMITED, SAMPLED, or DETAILED

select *
from sys.dm_db_index_physical_stats(@db_id,@object_id,@index_id,null,@Model) ips
order by ips.index_id

Appendix:
Scanning Modes

The mode in which the function is executed determines the level of scanning performed to obtain the statistical data that is used by the function. mode is specified as LIMITED, SAMPLED, or DETAILED. The function traverses the page chains for the allocation units that make up the specified partitions of the table or index. sys.dm_db_index_physical_stats requires only an Intent-Shared (IS) table lock, regardless of the mode that it runs in.

The LIMITED mode is the fastest mode and scans the smallest number of pages. For an index, only the parent-level pages of the B-tree (that is, the pages above the leaf level) are scanned. For a heap, the associated PFS and IAM pages are examined and the data pages of a heap are scanned in LIMITED mode.

With LIMITED mode, compressed_page_count is NULL because the Database Engine only scans non-leaf pages of the B-tree and the IAM and PFS pages of the heap. Use SAMPLED mode to get an estimated value for compressed_page_count, and use DETAILED mode to get the actual value for compressed_page_count. The SAMPLED mode returns statistics based on a 1 percent sample of all the pages in the index or heap. Results in SAMPLED mode should be regarded as approximate. If the index or heap has fewer than 10,000 pages, DETAILED mode is used instead of SAMPLED.

The DETAILED mode scans all pages and returns all statistics.

The modes are progressively slower from LIMITED to DETAILED, because more work is performed in each mode. To quickly gauge the size or fragmentation level of a table or index, use the LIMITED mode. It is the fastest and will not return a row for each nonleaf level in the IN_ROW_DATA allocation unit of the index.

参考文档:

sys.dm_db_index_physical_stats (Transact-SQL)

sys.index_columns (Transact-SQL)

时间: 2024-12-16 17:29:50

查看Table的Index的相关文章

转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Usage – A Simple Note oracle表访问方式 Index Seek和Index Scan的区别以及适用情况 1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找

lua table integer index 特性

table.maxn (table) Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices. (To do its job this function does a linear traversal of the whole table.) 返回表中最大的正数值index. 说明: 1. 此接口不是统计表中元素的

table中index、newindex、rawget、rawset的一段代码及理解

1 print("lua 中 table 就是一种对象的体现") 2 3 4 function string:xsplite( delimiter ) 5 local tmptb = {} 6 if self == nil or self=='' or delimiter==nil then 7 return nil 8 elseif delimiter == '' then 9 table.insert(tmptb,self) 10 return tmptb 11 else 12 s

批量修改table和index 的表空间

由于开发人员把ess 项目下的大部分对象放到user 表空间中,用imp/exp 导入正式库后,ess用户的对象还是在users 表空间中.为了把ESS 的对象放到ess 默认的表空间ess中,我按如下几步操作: 1 找出要修改表空间的对象: select * from dba_tables  where owner='ESS' and tablespace_name = 'USERS'; select * from dba_INDEXES where table_owner='ESS' and

create index 与 alter table add index 区别

众所周知,MySQL创建索引有两种语法,即:ALTER TABLE HeadOfState ADD INDEX (LastName, FirstName);CREATE INDEX index_name HeadOfState (LastName, FirstName);那么,这两种语法有什么区别呢? 在网上找了一下,在一个英文网站上,总结了下面几个区别,我翻译出来,如下:1.CREATE INDEX必须提供索引名,对于ALTER TABLE,将会自动创建,如果你不提供:2.CREATE IND

Oracle通过SQL语句查看table所引用的对象(View/Function/Procedure/Trigger)

通过使用user_dependencies进行查看,如下: SELECT * FROM user_dependencies WHERE referenced_name='SFCUSN' --Table_name 效果如下: 原文地址:https://www.cnblogs.com/LuckyZLi/p/10788402.html

查看table,view,procedure的定义

select object_definition(object_id('sys.tables')) exec sp_helptext 'sys.tables' select * from sys.system_sql_modules where object_id=object_id('sys.tables')

The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'

今天查看Job的History,发现Job 运行失败,错误信息是:“The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'.” 错误消息表明:数据库的事务日志文件空间耗尽,log 文件不能再存储新的transaction log. SQL Server将事务日志文件在逻辑上划分为多个VLF(Virtual Log Files),将这些VLF组成一个的环形结构,以VLF为重用单元.如果一个VLF 中存在

查询数据库,表和磁盘的使用情况

总结下查询数据库,表和磁盘的使用情况. 1.如下,可以看到第一列是磁盘名称,第二列是该磁盘剩余的空间,单位是 M exec sys.xp_fixeddrives 2.使用系统SP:exec sys.sp_spaceused 如果后面不接任何对象,则返回整个数据库的情况 exec sys.sp_spaceused 注:database_size是所有数据库文件大小+日志文件的大小,unallocated space指的是数据库还未使用的空间,如果这部分空间很大,可以考虑压缩数据库,当然,datab