devxlogo

SQL

Statistics IO and Statistics Time

STATISTICS IO?and STATISTICS TIME?show the amount of time spent on a query and the reads and writes of the query in question. This is good to know for quick performance

Print All Table Column Definitions in an Entire Database

The following script can be used to print all column definitions for all the tables in your database. SELECTsys.schemas.name + ‘.’ + sys.objects.name AS TableName,sys.columns.name as ColumnName,CASEWHEN sys.types.name IN (‘char’,’varchar’)

Finding All Currently Blocked Requests in SQL

Here is a quick way to find all currently blocked requests in SQL: SELECTSESSION_ID,STATUS,BLOCKING_SESSION_ID,WAIT_TYPE,WAIT_TIME,WAIT_RESOURCE,TRANSACTION_IDFROM sys.dm_exec_requestsWHERE STATUS = N’suspended’;GO

Using dm_exec_function_stats in SQL Server 2016

You can use the dm_exec_function_stats (in SQL Server 2016) to check detailed execution details of a function. These include: execution_count – the number of times this function has been executedlast_execution_time

Identify Tables Without an Identity Column

The following query will enable you to list all the tables in your database that doesn’t have an IDENTITY Column: SELECT SysSchemas.name + N’.’ + SysTables.name FROM sys.tables AS SysTables