How to capture messages | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to capture messages

Hi All, I am wondering if there is a way to trap messages from a SQL Query into a table of some sort. For example, I am running DBCC CHECKDB and would like to know if i can capture this output into a table: DBCC results for ‘TableA’.
There are 121 rows in 7 pages for object ‘ShowContig’.
DBCC execution completed. If DBCC printed error messages, contact your system administrator. Since its not a result set, im not sure how to trap it and using this won’t work either: create table output (description text)
declare @cmd varchar (255)
set @cmd=’dbcc checktable (”TableA”)’ insert into output
exec (@cmd) Thanks in advance.
Take a look the following article: You can find how Tom capture DBCC. Luis Martin
Moderator One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important
Bertrand Russell
All postings are provided “AS IS” with no warranties for accuracy.
Yup i know i can capture showcontig since it has the TABRESULTS option but DBCC CHECKTABLE does not. I guess my question is specific to CHECKTABLE since it doesnt output the result as a resultset but as a message – i would like to know how to capture this message besides using a logfile. thanks!
Thanks to a buddy, found a solution:
exec master..xp_cmdshell ‘OSQL -E -dDBA -SServerANamed1 -Q"dbcc checktable(”[dbo].[TableA]”)"’ Will return results as a resultset which i can capture in a temp table.