Trigger to insert data into a notepad

  • Good Day All

    I want to create a trigger that will send records INSERTED into a notepad.  Can you please help with the syntax

    CREATE TRIGGER Test ON [Table1]

    FOR INSERT

    NOT FOR REPLICATION

    AS

    /*Instead of Inserting into another table, I WANT TO INSERT DATA INTO A NOTE PAD */

     

  • I assume you are talking about writing some details to a text file. Try this ...this is from BOL.

    E. Write variable contents to a file

    This example writes the contents of the @var variable to a file named var_out.txt in the current server directory.

    DECLARE @cmd sysname, @var sysnameSET @var = 'Hello world'SET @cmd = 'echo ' + @var + ' > var_out.txt'EXEC master..xp_cmdshell @cmd
    I guess you might have to use xp_cmdshell. check out BOL for further details.
    Cheers!


    Arvind

  • With a bit of work, you can also set up a linked server connection to a text file instead of resorting to xp_cmdshell. An example is given of how to set up such a connection in Books Online under the system stored procedure sp_addlinkedserver.

    K. Brian Kelley
    @kbriankelley

  • Thats cool Brian! Didnt know that cud be done.

    Cheers!


    Arvind

  • Warning on that, though; potential performance problems, as you're making the completion of a transaction dependent on external processes completing.

    cl

    Signature is NULL

  • Agreed. It is probably better here to load the data to a table from the trigger and then have an automated process pull the information asynchronous from the user.

    K. Brian Kelley
    @kbriankelley

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

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