[Reprint] How to see how much tempdb space a query uses

Source: Internet
Author: User

Http://www.cnblogs.com/CareySon/p/3910337.html

The following script allows you to view the space of a query's useful tempdb.

The first step is to find out what the current tempdb utility space is,

The second step is to execute a query statement

The third step is to use the yourselves tempdb space-the first step to tempdb practical space.

DECLARE @read BIGINT, @write BIGINT; SELECT @read=SUM (num_of_bytes_read), @write=SUM (Num_of_bytes_written) from Tempdb.sys.database_files as Dbfjoin sys.dm_io_virtual_file_stats (2, NULL) As FS on fs.file_id=Dbf.file_idwhere Dbf.type_desc='ROWS'--here, put the statement that needs to be measured select TEMPDB_READ_MB= (SUM (num_of_bytes_read)-@read)/1024x768. /1024x768., TEMPDB_WRITE_MB= (SUM (num_of_bytes_written)-@write)/1024x768. /1024x768., INTERNAL_USE_MB=(SELECT internal_objects_alloc_page_count/128.0From sys.dm_db_task_space_usage WHERE session_id=@ @SPID) From Tempdb.sys.database_files as Dbfjoin sys.dm_io_virtual_file_stats (2, NULL) As FS on fs.file_id=Dbf.file_idwhere Dbf.type_desc='ROWS'
View Code

[Reprint] How to see how much tempdb space a query uses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.