If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Triggers Newbie

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-09, 14:54
dc_duo12 dc_duo12 is offline
Registered User
 
Join Date: Apr 2009
Posts: 1
Triggers Newbie

Hi guys,

Just wandering if you could help me with a mysql trigger. Its my first time coding a trigger so any help would be appreciated. I tried reading the mysql docs but find them a bit overwhelming, i tend to respond better to examples me self.

What I am trying to do is insert into a table of users which is all good. However what I would like the trigger to do is check the submitted nice name (which is a hyphonated lower case string formed by the user submitted name and surname) and see if there is another instance of this, if there is then update the newly submitted value to be first-surname-THE ID OF THE ROW

Any help would be appreciated on this, as I would rather start using triggers and such to update tables rather than have reams of PHP mysql statments overloading the server.

Cheers Chaps

Steve
Reply With Quote
  #2 (permalink)  
Old 05-07-09, 05:18
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
I don't know the MySQL language, but what you need is an INSTEAD OF trigger, that MySQL doesn't have yet. A normal trigger does not have the ability to update its own table (or to transform the INSERT statement into an UPDATE one).
__________________
Florin Aparaschivei
Iasi, Romania
Reply With Quote
  #3 (permalink)  
Old 05-07-09, 07:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you do not need a trigger for this

read about INSERT syntax in da manual, and pay particular attention to the ON DUPLICATE KEY UPDATE option

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On