sqlserver 常用语句

时间:2024-06-01 18:02:50

1.查询表中的RID

RID=RowID=(fileID:pageID:slotID)

SELECT sys.fn_PhysLocFormatter(%%physloc%%) AS rid,* FROM person

2.开启DBCC命令语法

--开启
DBCC TRACEON(2588)
--帮助命令
DBCC HELP('IND')

3.开启导出数据页语法

--开启
DBCC TRACEON(3604);
--导出数据页
DBCC PAGE(test,1,262,2);

4.索引的统计信息

DBCC SHOW_STATISTICS(test1,idx_test1);

5.查询锁

SELECT * FROM sys.sysprocesses WHERE spid IN (63,60)

SELECT request_session_id, resource_type,
request_status, request_mode,
resource_description, object_name(p.object_id) as object_name,p.index_id
FROM sys.dm_tran_locks left join sys.partitions p
on sys.dm_tran_locks.resource_associated_entity_id = p.hobt_id
WHERE request_session_id IN (63,60)

6.查询解析树/执行计划

SELECT  CP.usecounts AS CountOfQueryExecution ,
CP.cacheobjtype AS CacheObjectType ,
CP.objtype AS ObjectType ,
ST.text AS QueryText
FROM sys.dm_exec_cached_plans AS CP
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS ST
WHERE CP.usecounts > 0