How to write a message to the SQL Server 2008 R1 error log from TSQL

  • Can anyone tell me if there is a way to write a message to the SQL Server 2008 R1 error log from TSQL?

  • RAISERROR ... WITH LOG

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hmm. I hadn't thought about RAISERROR. Won't that kill the current batch too though?

  • This seems to work without killing the batch.

    raiserror ('test', 0, 0) with log;

    Thanks for the tip, Gail!

  • Anything with a Severity <= 10 will be treated as "informational" and will not affect batch execution (i.e. will not set @@error). It will however cause data to be sent to the caller on the info messages stream which can trip up some less-savvy data access layers.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply