Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Posts
    3

    Unanswered: Where do we write a Trigger

    Hi,
    I am pretty new to MSSQL server environment. In Oracle i write Trigger and compile it at command prompt in case of SQL plus the same way i need to know where we write the script for SQL server. Is there any menu driven editor where we can write or simply writing a trigger in SQL Query analyzer and executing it will work

    Please advice.

    Thanks and Regards
    D. Pavan Kumar

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Try asking in the SQL Server Forum,
    ill see if a moderator will move this for you

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    [ moderator comment: sorry, didn't see this until today ]
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Quote Originally Posted by pavanmadhu
    Is there any menu driven editor where we can write or simply writing a trigger in SQL Query analyzer and executing it will work

    Please advice.

    Thanks and Regards
    D. Pavan Kumar
    Within Query Analyzer, code your trigger and then execute. If written properly, it will be associated with the proper table and execute when the coded action occurs. For example, here is a delete trigger template:

    Code:
    CREATE TRIGGER [table99_Delete] ON dbo.table99
    FOR DELETE
    AS
    /* =======================================================================================
    // Application Unit: ?????????
    //
    // Description:  ?????????
    //
    //---------------------------------------------------------------------------------------
    //
    // $Author:  $
    // $Date: 12/08/04 4:50p $
    // $Revision: 7 $
    //======================================================================================= */
     
    -- Skip all triggers if current user is NoTriggerUser
    if upper( CURRENT_USER )  = 'NoTriggerUser'  
       GOTO End_Of_Trigger
    
    update table99
    set moddate = getdate()
    where inserted.clusteredindex = dbo.table99.clusteredindex
     
    End_Of_Trigger:
    -- DO NOT PUT ANY CODE BELOW THIS LINE !!!!!!!!!!!

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Trigger in SQL Server

    See the attached word doc on where to write the trigger (right click on the table you want to write the trigger on.) I then link in the tables in Access and test it out to see if it works on the linked tables.
    Attached Files Attached Files
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •