By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

How to stop adding/updating duplicate username and email?

P: 9
Hello,

I am creating a web application in which registrations are open as usual. My doubt is, if some one try to create an account by an email-id like 'foo@gmail.com', at same time other user also try to create account by same emailid 'foo@gmail.com', what will happen in this case? I have added a validation to check the duplicate email-id in the database before insert and update in my script but i am thinking if both request submitted on same time then what will happen? will PostgreSQL add both records into the table? Please suggest me how to handle such situations?

I heard that such type of problem can be prevent by row locking. Could you please help me to sort out it?

Mangal Kumar
Nov 15 '11 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 700
Create a unique index or primary key on the email-id field and you will not have to check for duplicates, database will do it such validation for you. After inserting a row you can catch an exception and show user a message that such email already exists.
Nov 15 '11 #2

P: 9
Thank you

I will try it.
Nov 18 '11 #3

P: 1
rski, thanks a lot for your answer! i find it also pretty useful! Very good!


_________________
<link removed by moderator>
Aug 22 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.