SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Trigger

  1. #1
    SitePoint Enthusiast edgarzakaryan's Avatar
    Join Date
    Aug 2012
    Location
    Yerevan, Armenia
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Trigger

    Hello.
    I need to create trigger that will run after select.

    I wrote this

    Code:
    DROP TRIGGER IF EXISTS `article_after_select`;
    
    DELIMITER $$
    
    CREATE
        TRIGGER `article_after_select` AFTER SELECT ON `article` 
        FOR EACH ROW BEGIN
        /*SOME ACTION HERE*/	
    END;
    $$
    
    DELIMITER ;
    I need when article selected, update view count.
    But I can't create trigger for SELECT.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by edgarzakaryan View Post
    But I can't create trigger for SELECT.
    you'll have to do it with your application language (php or whatever)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast edgarzakaryan's Avatar
    Join Date
    Aug 2012
    Location
    Yerevan, Armenia
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay r937.
    I just don't understand why it's working for delete, update, insert but not for select.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by edgarzakaryan View Post
    I just don't understand why it's working for delete, update, insert but not for select.
    because the syntax doesn't allow it


    excerpt from the mysql manual --
    Code:
    CREATE
        [DEFINER = { user | CURRENT_USER }]
        TRIGGER trigger_name trigger_time trigger_event
        ON tbl_name FOR EACH ROW trigger_stmt
    trigger_event indicates the kind of statement that activates the trigger. The trigger_event can be one of the following:

    INSERT: The trigger is activated whenever a new row is inserted into the table; for example, through INSERT, LOAD DATA, and REPLACE statements.

    UPDATE: The trigger is activated whenever a row is modified; for example, through UPDATE statements.

    DELETE: The trigger is activated whenever a row is deleted from the table; for example, through DELETE and REPLACE statements.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Tags for this Thread

Bookmarks

Posting Permissions

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