How do I create a trigger in a stored procedure?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I want a stored procedure to:

1) Delete existing trigger on TableA
2) Run an Update SQL for certain fields in TableA (cleaning table)
3) Recreate the trigger

It's giving me the following error though:

Msg 156, Level 15, State 1, Procedure uspGeneralLanguageMaintenanceAutoValuesClean, Line 19
Incorrect syntax near the keyword 'Trigger'.



ALTER PROCEDURE [dbo].[uspGeneralLanguageMaintenanceAutoValuesClean]
AS

/****** 1)

IF EXISTS (SELECT * FROM sys.triggers WHERE object_id =
OBJECT_ID(N'[dbo].[LanguageValuesTrigger]'))
DROP TRIGGER [dbo].[LanguageValuesTrigger]


/****** 2)

UPDATE tblLanguageValues
SET LanguageText = REPLACE(LanguageText,'"', '"')
WHERE (LanguageCode <> 'EN-US')

UPDATE tblLanguageValues
SET LanguageText = REPLACE(LanguageText,'&#39;', char(39))
WHERE (LanguageCode <> 'EN-US')

/****** 3)
create Trigger [dbo].[LanguageValuesTrigger] On [dbo].[tblLanguageValues]
After Update As
Begin
Update LV
Set ToDo = 1, LastUpdatedBy = 'Needs Refresh'
From dbo.tblLanguageValues LV
Inner Join inserted i On LV.LookupID = i.LookupID
Inner Join deleted d On i.LookupID = d.LookupID And i.LanguageText <>
d.LanguageText
Where i.LanguageCode = 'en-US'
And LV.LanguageCode <> 'en-US';
End;








.



Relevant Pages

  • Re: chooses not to generate code at all
    ... >>>DBMS is so that the DBMS engine can execute it when triggered by some ... If there is no trigger, ... Stored procedure is one thing. ... > If the procedure execution is not triggered by DBMS ...
    (comp.object)
  • Parameterised Input stored procedure
    ... I need to create a stored procedure with a parameterised input. ... wants to insert from TableA into TableB. ... Item_ID as int ... -- If item exist, and Qty is not 0, then insert into TableB and Update ...
    (comp.databases.ms-sqlserver)
  • Re: Insert Error 30014
    ... of @@identity before the stored procedure finish: ... the trigger. ... I have a form where I want to have underlying record source of a single ... EventId ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Insert Error 30014
    ... of @@identity before the stored procedure finish: ... the trigger. ... >> I have a form where I want to have underlying record source of a>> single ... >> EventId ...
    (microsoft.public.access.adp.sqlserver)
  • Re: SSE 2008: Handling Transaction Batches
    ... SQL as well. ... But not all rules are easily expressed with a constraint. ... A trigger can more easily disappear than a constraint. ... A stored procedure on the other hand is an autonomous module and is ...
    (comp.databases.ms-sqlserver)