A general logging t-sql process to write to .txt files | Database Journal

A general logging t-sql process to write to .txt files

Written By
Mike Metcalf
Mike Metcalf
Oct 11, 2000
1 minute read

In my previous article, I walked you through a general logging process to write out simple logging information to a table so that it could read/reported on, etc. You can see it be clicking here. But I actually got a few responses from people who want to be able to log directly to .txt files.

I thought about for a while… My initial thought was to write all of the log stuff out to a temporary table then bcp it out… but I figured that could be overkill and potentially cumbersome to implement, especially if the .txt file you want write to already exists. So I thought about it a little more came up with this simple variation on my table-based logging process that will allow you to write logging information to general .txt files. This could be used any place T-SQL is welcome (stored procedures, query windows, triggers, and SQL Query Windows within DTS).

Here I’ll outline: The process, Why it works, Caveats

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.