Logging by TSQL

  • Howdy,

    New to sql server.

    I have a sql server script that needs to run. It runs fine. but it doesn't have any logging statements in it. can some show me how to write to log onto file server when the script runs.

    this is the script I have and I want to write to an ascii file (on file server), the timestamp when this script started running and the content of @TableName and timestamp when this script ended running.

    Thanks

    DECLARE @TableName varchar(255)

    DECLARE TableCursor CURSOR FOR

    SELECT table_name FROM information_schema.tables

    where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = 'dbo'

    OPEN TableCursor

    FETCH NEXT FROM TableCursor INTO @TableName

    WHILE @@FETCH_STATUS = 0

    BEGIN

    DBCC DBREINDEX(@TableName,' ',90)

    FETCH NEXT FROM TableCursor INTO @TableName

    END

    CLOSE TableCursor

    DEALLOCATE TableCursor

  • Please do NOT waste people's time by cross-posting!!!

    All: do not respond to this post; please use http://www.sqlservercentral.com/Forums/Topic1025402-391-1.aspx.

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • Ray K (11/23/2010)


    Please do NOT waste people's time by cross-posting!!!

    All: do not respond to this post; please use http://www.sqlservercentral.com/Forums/Topic1025402-391-1.aspx.

    Whoa! No need to yell, Ray. And considering the OP only has 3 posts, you might want to take the time to explain why cross-posting is such a bad idea. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 3 (of 3 total)

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