Tutorial by Examples

To retrieve a list of all servers registered on the instance: EXEC sp_helpserver;
sp_who2 This procedure can be used to find information on current SQL server sessions. Since it is a procedure, it's often helpful to store the results into a temporary table or table variable so one can order, filter, and transform the results as needed. The below can be used for a queryable v...
SELECT SERVERPROPERTY('ProductVersion') AS ProductVersion, SERVERPROPERTY('ProductLevel') AS ProductLevel, SERVERPROPERTY('Edition') AS Edition, SERVERPROPERTY('EngineEdition') AS EngineEdition;
SELECT DATEDIFF(DAY, login_time, getdate()) UpDays FROM master..sysprocesses WHERE spid = 1
To discover SQL Server's edition, product level and version number as well as the host machine name and the server type: SELECT SERVERPROPERTY('MachineName') AS Host, SERVERPROPERTY('InstanceName') AS Instance, DB_NAME() AS DatabaseContext, SERVERPROPERTY('Editio...
Query to search last executed sp's in db SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql ORDER BY execquery.last_execution_time DESC Query to search thro...

Page 1 of 1