Output SQL messages to a Log File

18,583

Solution 1

You can run scripts from the Command line using SQLCMD utility.

http://msdn.microsoft.com/en-us/library/ms162773%28SQL.90%29.aspx

You can run this through a batch file. It let's you log to a file.

You can automate such jobs using scheduling programs.

Solution 2

In SSMS, click Query->Results To...->Results To File

Share:
18,583

Related videos on Youtube

Davie
Author by

Davie

Systems designer for an I.T. company in the UK.

Updated on June 04, 2022

Comments

  • Davie
    Davie about 2 years

    I have an SQL script than runs a couple of DBBC commands. Is there a way to send the messages generated from executing these commands to a simple log file e.g "C:\log.txt"?

    The messages I mean are the ones that appear in the messages box at the bottom of SQL Server 2005 Management Studio after a query has executed.

    The reason for needing to do this is because I don't intend on having SQL Server Management Studio open so the messages can't be seen.

    I am using SQL Server 2005 if that helps.

  • mikhail-t
    mikhail-t over 6 years
    Please provide more details on your answer, e.g. how to install/use sqlcmd, explanation of parameters, what version of SQL Server you've been able to use it on, etc.
  • Nielsvh
    Nielsvh almost 3 years
    The question isn't asking about results. Commands like PRINT, for example, don't output results and row counts from INSERT or UPDATE also aren't results unless you specify the OUTPUT of those commands.