Creating multiple triggers within a stored procedure


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Creating multiple triggers within a stored procedure

  1. #1
    franka Guest

    Creating multiple triggers within a stored procedure


    I'm trying to write a stored procedure that creates several triggers. Whenever
    I try to save the stored procedure I get a "incorrect syntax near the keyword
    'Trigger'. If I paste the CREATE TRIGGER statements into the Query Analyzer
    that run fine. It appears that the syntax error is being generated when
    it reads the 2nd CREATE TRIGGER statement. Any ideas??

  2. #2
    DaveSatz Guest

    Re: Creating multiple triggers within a stored procedure

    from BOL under CREATE TRIGGER
    Trigger Limitations
    CREATE TRIGGER must be the first statement in the batch and can apply to
    only one table.

    maybe if used either SQL DMO (outside TSQL) or dynamic SQL to execute each
    CREATE TRIGGER it would work.



    --

    HTH,
    David Satz
    Principal Software Engineer
    Hyperion Solutions
    { SQL Server 2000 SP1/7.0 SP3/6.5 SP5a } { Cold Fusion 5/4.5.1 SP2 } { VSS }
    (Please reply to group only - emails answered rarely)
    This posting is provided "AS IS" with no warranties, and confers no rights.
    You assume all risk for your use.
    -----------------------------------------------------------------

    "franka" <fea@robinson-consulting.com> wrote in message
    news:3baf8b48$1@news.devx.com...
    >
    > I'm trying to write a stored procedure that creates several triggers.

    Whenever
    > I try to save the stored procedure I get a "incorrect syntax near the

    keyword
    > 'Trigger'. If I paste the CREATE TRIGGER statements into the Query

    Analyzer
    > that run fine. It appears that the syntax error is being generated when
    > it reads the 2nd CREATE TRIGGER statement. Any ideas??




  3. #3
    Johan Guest

    Re: Creating multiple triggers within a stored procedure


    Hi,

    Try seperating your CREATE TRIGGER statements with the GO statement.

    Regards
    Johan


    "franka" <fea@robinson-consulting.com> wrote:
    >
    >I'm trying to write a stored procedure that creates several triggers. Whenever
    >I try to save the stored procedure I get a "incorrect syntax near the keyword
    >'Trigger'. If I paste the CREATE TRIGGER statements into the Query Analyzer
    >that run fine. It appears that the syntax error is being generated when
    >it reads the 2nd CREATE TRIGGER statement. Any ideas??



  4. #4
    Doug Buchanan Guest

    Re: Creating multiple triggers within a stored procedure

    Go is for batch SQL statements, not SPs

    "Johan" <johan.grobler@ensemble.co.za> wrote in message
    news:3bb1b84a$1@news.devx.com...
    >
    > Hi,
    >
    > Try seperating your CREATE TRIGGER statements with the GO statement.
    >
    > Regards
    > Johan
    >
    >
    > "franka" <fea@robinson-consulting.com> wrote:
    > >
    > >I'm trying to write a stored procedure that creates several triggers.

    Whenever
    > >I try to save the stored procedure I get a "incorrect syntax near the

    keyword
    > >'Trigger'. If I paste the CREATE TRIGGER statements into the Query

    Analyzer
    > >that run fine. It appears that the syntax error is being generated when
    > >it reads the 2nd CREATE TRIGGER statement. Any ideas??

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center