Create Trigger within T-SQL statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Barno77
    New Member
    • Oct 2007
    • 22

    #1

    Create Trigger within T-SQL statement

    How can I Create a Trigger that will be nested within T-SQL or another trigger? Thanks for any help!
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    What exactly you are trying to achieve by writing a nested trigger ?

    Comment

    • Barno77
      New Member
      • Oct 2007
      • 22

      #3
      Originally posted by debasisdas
      What exactly you are trying to achieve by writing a nested trigger ?
      I'm basically checking to see if a trigger exists and if it doesn't then I'm gonna get an email and I want to create that trigger. Any ideas? Check my code below:

      Declare @Body as varchar(125)
      Declare @NumRecs as numeric(9)
      select
      @NumRecs = COUNT(name)
      from
      dbo.sysobjects
      where
      OBJECTPROPERTY( id, N'IsTrigger') = 1 and name = 'TR_JUNK2'
      select @NumRecs
      Set @Body = 'Trigger TR_SO1_TO_CHANG E_LOG missing from table SO1_SOEntryHead er'

      IF @NumRecs < 1
      BEGIN
      EXEC CDO_SendMail 'MyEmail@email. com', @Body, 'Missing Trigger'

      CREATE TRIGGER [TR_JUNK2] ON [dbo].[SO9_TEST] FOR DELETE
      AS
      select '1'

      END

      Comment

      Working...