Sql-server – How do query notifications detect changes in the query result

service-brokersql serversql-server-2005

I am working with a legacy database that has implemented query notifications against a table called ColorList.

While running a server-side trace for an unrelated issue, I noticed the query

SELECT color FROM ColorList

was being executed every 10 milliseconds.

Is this how Query Notification works? Does SQL Server store the results of the original query and then run the query endlessly until it detects a change?

Best Answer

Read the Mysterious Notification for an explanation on how it works. If you see the query executed every 10ms it means your application is running it every 10ms. My 8 ball is telling me your code does not check the notification EventArgs and is blindly resubmitting the query despite the Info being of the value Invalid, indicating a query than cannot be notified. Which is to be expected, since your query does not conform to the Query Notification restrictions:

The projected columns in the SELECT statement must be explicitly stated, and table names must be qualified with two-part names.