How to Use the BETWEEN Operator in SQL Server

The SQL Server BETWEEN operator allows you to test between a range of values in your queries. For example, you could test that a value is between two numbers.

The BETWEEN operator is inclusive, meaning that it includes the values that you specify within the range. That is, it includes values that are greater than or equal to the lower value, and values that are less than or equal to the higher value. Therefore it’s like using >= and <=.

Continue reading

How sys.dm_exec_describe_first_result_set_for_object Works in SQL Server

In SQL Server, the sys.dm_exec_describe_first_result_set_for_object dynamic management function returns the metadata of the first result set for a given module.

It takes an @object_id as a parameter and describes the first result metadata for the module with that ID.

It uses the same algorithm as the sp_describe_first_result_set system stored procedure and the sys.dm_exec_describe_first_result_set function, and does pretty much the same thing, except that it’s limited to just stored procedures and triggers.

If you pass the ID of a different object type (such as a view, function, table, etc) then it will return an error.

Continue reading

How sys.dm_exec_describe_first_result_set Works in SQL Server

In SQL Server, the sys.dm_exec_describe_first_result_set dynamic management function returns the metadata of the first result set for a given T-SQL statement or statements.

This function uses the same algorithm as the sp_describe_first_result_set system stored procedure, and does pretty much the same thing.

It accepts three parameters, the first of which is the T-SQL statement/s you’re analysing.

Continue reading

Estimate Data Compression Savings in SQL Server

SQL Server has a system stored procedure called sp_estimate_data_compression_savings, which allows you to check an object’s size and its estimated size with various levels of compression.

If the object is already compressed, you can use this procedure to estimate its size when recompressed.

Objects can be compressed by using row, page, columnstore or columnstore archive compression.

Compression can be evaluated for whole tables or parts of tables. This includes heaps, clustered indexes, nonclustered indexes, columnstore indexes, indexed views, and table and index partitions.

Continue reading

What is STATISTICS XML in SQL Server?

In SQL Server, you can use the SET STATISTICS XML statement to generate detailed information about how a T-SQL statement was executed.

This information is provided in the form of a well formed XML document.

Once SET STATISTICS XML is set to ON, each subsequent statement is reflected in the output by a single XML document.

Each XML document contains the text of the statement, followed by the details of the execution steps.

The output shows run-time information such as the costs, accessed indexes, and types of operations performed, join order, the number of times a physical operation is performed, the number of rows each physical operator produced, and more.

Continue reading