Contents of a script file and output file into a table

  • Hi,

    I'm trying to keep a copy of all scripts run against a database and their output into a table, but I'm having difficulty keeping the scripts and the output. I can read the contents of a file into a database, but I'm used to it being many lines for many rows. In this case I want the script, line breaks and all, in a single row. Does anyone have any experience with this? As of right now I'm trying to update an existing table record after the fact, but I'm open to anything. I think if I can get the script read in I should be able to do the same with the output.

    Here's the t-sql for the table:

    CREATE TABLE [dbo].[zScriptExecutions](

    [ScriptExecutionID] [int] IDENTITY(1,1) NOT NULL,

    [Name] [nchar](200) NOT NULL,

    [ExecutionDateTime] [datetime] NOT NULL,

    [ChangeRequest] [varchar](10) NULL,

    [ExecutedBy] [varchar](200) NULL,

    [Comments] [nvarchar](max) NULL,

    [ScriptContent] [nvarchar](max) NULL,

    [ScriptResults] [nvarchar](max) NULL)

    any help would be appreciated.

    Thanks,

  • I suggest you write down a trigger on the database.

  • What are you using to "read the contents of a file into the database" that brings it in as one row per line?

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

  • Bulk insert. I've found a solution, will post when I have a computer.

  • A lean Sql Trace definition should fetch you the TSql run against the database.

    Why you would want to capture output is one I don't quite understand...

    Assuming a script returns a large number of rows.. you intend to capture and store this?

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

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