tags:

views:

74

answers:

7

In order to the determine the 'liveliness' of a remote SQL-server, I need to periodically address the server with some query.

I am looking for a query which will generate minimal server work, and minimal communications overhead (both for the query and the reply).

The query should work on SQL-Server 2005 and 2008 at least, and should not assume existance of some database or table, and should not generate errors.

A: 

select count(*) from "smallest table you have access to"

ennuikiller
That introduces table and database dependencies.
Raj More
+1  A: 
SELECT 1+1

though you should be able to check whether the server is responding without performing a query.

Aaron
+6  A: 

How about:

select 1
Andrejs Cainikovs
A: 

select spid from master..sysprocesses

Matt Wrock
A: 
SELECT GetDate()
Raj More
+6  A: 

Andrejs Cainikovs answer of select 1 is good. No database or table dependencies, minimal data, etc.

A couple of days ago, I ran a SQL Profiler on a SQL Server 2005 server, and one of the SQL Statements that I saw every few secons was: SELECT N'Testing Connection...' which has the advantage of documentation for someone observing the server. So maybe something like:

select 'Testing connection from server Y for application X'

A little more data would need to be put on the wire, but it would allow anyone profiling the server to know exactly why those selects were showing up.

Shannon Severance
Consider adding @@SERVERNAME to your SELECT.
Rob Garrison
@Rod: Why? I'm presuming that the calling routine already knows which server it is calling.
Shannon Severance
A: 

SELECT @@SERVERNAME as ServerName

rab