Wednesday, March 28, 2012

How do I know if there is a duplicate value in database

hello, i am creating a user login system. When people register for the site I need a way for sql to check weather or not their is a duplicate username already in the databse. Currently, I am going through the whole member profile table searching for a duplicate name. Is there a better way to do this?i am not sure how u r performing the check and what is bothering u. however, u can create a unique index on that field and fire the insert without any check. a duplicate value will produce an error.|||Currently, I am going through the whole member profile table searching for a duplicate name. Is there a better way to do this?
If for some strange reason the unique index (actually this should be the primary key) is not an option for you, why do you "go through the whole table"?.
A simple

SELECT couint(*) from user_profile WHERE username = 'input_value';

will also tell you if there is another row with that username.|||hello, i am creating a user login system. When people register for the site I need a way for sql to check weather or not their is a duplicate username already in the databse. Currently, I am going through the whole member profile table searching for a duplicate name. Is there a better way to do this?

SELECT username, count(*)
FROM tblLogins
GROUP BY username
HAVING COUNT(*) > 1|||INSERT INTO Table(Collist) SELECT values
SELECT @.error = @.@.ERROR
IF @.@.ERROR <> 0
BEGIN
Error Handling|||hmmmm..so which way is the fastest and most efficient?|||I'd say the most efficient would be the unique index (or primary key) option, because, with correct error handling, not only can you prevent the problem from occurring, you can also provide a meaningful error message to users.sql

No comments:

Post a Comment