Click here to Skip to main content
14,869,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all i am using triggers firsttime.
i have a table name login in which i want to fire trigger before new registration.the trigger will check if the new username already exist and will restrict the new entry if the user already exist and will show a message that user already exist.plz help.
Posted

Why you are not using stored procedure? As per your requirement this is a perfect place to implement Stored Procedure.....and last of all using trigger you can't show a message that the user exists or not...

For more concept about trigger and where to use it and how to use it please go to the following links

http://dev.mysql.com/doc/refman/5.0/en/triggers.html[^]

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html[^]
   
Hi Mylogics,

My question is why you are adding a trigger to check existing records.
you can just check in query in same sp that is you are using to inserts records in db table.

to create trigger you can write code as

CSS
CREATE TRIGGER trgname
BEFORE INSERT ON my_table_name
FOR EACH ROW
BEGIN
IF something THEN
#do somthing
END IF;
END;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900