How do use SQLCMD to run a simple (CREATE or ALTER Trigger) scripts

  • I have a bunch of Triggers I created, but I don't want to open each one and hit execute... In an early post I did, someone suggested the below... but it isn't working... I'm using SQL Server Management Studio 2005 on a SQL Server 2000 DB...

    Each Script is eithr ALTER TRIGGER or CREATE TRIGGER

    SQLCMD -i Y:\ALLL\NewTrigger4ColumnUpdates\trg_I_tblRptLevel_AuditUpdates.sql

    sqlcmd -?

    USE [CPMTest]

    GO

    /****** Object: Trigger [dbo].[TABLE_NAME] Script Date: 10/10/2008 08:00:53 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET NOCOUNT ON

    GO

    CREATE TRIGGER [dbo].[TRIGGER_NAME]

    ON [dbo].[TABLE_NAME]

    --Author: John Steinbeck

    --Date: 24 Sept 08

    --Purpose: This Trigger is designed to capture any column whose value is updated... you will specify what columns you want

    --Version: v4

    --Change Desc: See Workbook - Y:\ALLL\BuildSQLTriggerUpdateColumnsFunctionV2.xls

    FOR DELETE

    AS

  • Each file has to be a query. It seems you have that. You use SQLCMD to just execute that query. The file contains the same thing that you would execute from SSMS if you had nothing highlighted and clicked Execute.

    The -i gives you the input file. That's your file name.

    The -Q parameter tells SQLCMD to run the file and then exit.

    You can use -0 to specify an output file for the errors and results.

  • ok, so i put it like this?

    SQLCMD -i Y:\ALLL\NewTrigger4ColumnUpdates\trg_I_tblRptLevel_AuditUpdates.sql -Q

    even with out the -Q i get an error

    Msg 170, Level 15, State 1, Line 1

    Line 1: Incorrect syntax near 'i'.

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

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