SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Create trigger for insert new record

    Hello everyone.

    I need your help for create trigger insert.

    Now I use this code ASP for insert new record in the table.

    This operation it's possible with trigger in the Mysql 5.0.45 version?

    Code:
      
       //QUERY TABLE _TEMP
       SQL = " SELECT * FROM "
       SQL = SQL & " _temp "
            
       Set Rs = CreateObject("ADODB.Recordset")
       Rs.Open SQL, cn
       
       if not Rs.eof then 
    
             Rs.MoveFirst()
               Do While Not Rs.EOF
             
               //QUERY FOR _TBL
               qs = "SELECT * FROM "
               qs = qs & " _tbl "
               qs = qs & " WHERE 1 "
               qs = qs & " AND DATES = '" & formatGMTDate(RS("DATES"),0,"yyyy-mm-dd") & "' "
    
               set RSqs = CreateObject("ADODB.Recordset")
               RSqs.Open qs, cn
               
               if not RSqs.eof And not RSqs.bof then
                  response.write "Nothing"
               
               else                      
                                    
               SQL = "INSERT INTO "  
               SQL = SQL & " _tbl " 
               SQL = SQL & "( "  
               SQL = SQL & "  DATES "
               SQL = SQL & " ) "  
               SQL = SQL & "  VALUES "  
               SQL = SQL & " (  "             
               SQL = SQL & " '" & formatGMTDate(Rs("DATES"),0,"yyyy-mm-dd") & "' "
               SQL = SQL & " ) "  
               cn.execute(sql)     
                  
               end if
                          
               RSqs.Close()
               set RSqs = Nothing
    
             Rs.MoveNext()
          Loop
    
       Rs.Close()
       Set Rs = Nothing
    
       cn.Close()
       Set cn = Nothing

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by cms9651 View Post
    This operation it's possible ... ?
    perhaps you could explain what this operation is supposed to do?

    i can't figure it out from your code
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    perhaps you could explain what this operation is supposed to do?

    i can't figure it out from your code
    Ok.

    I have two tables in mysql: _temp and _tbl.

    I need select all rows of table _temp and if row not exist in the table _tbl, insert the new row in _tbl.

    I have to analyze tables _temp and _tbl and insert news rows in the _tbl.

    Thanks.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by cms9651 View Post
    I need select all rows of table _temp and if row not exist in the table _tbl, insert the new row in _tbl.
    this does not seem to be the type of operation suitable for a trigger

    how often did you want to perform this operation?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    this does not seem to be the type of operation suitable for a trigger

    how often did you want to perform this operation?
    Running a day... I think that it is possible... I wrong... sorry


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
  •