Reputation: 33
I'm trying to error handle a registration aspx/c# page on my application and want to run a check whether the email address that a user has tried to register already exists as the email address is used as a primary key in my database.
I have tried IF NOT EXISTS/IF EXISTS but these dont give the desired effect so was wondering if there was another way around it?
Look forward to your reply,
Scott
Upvotes: 0
Views: 2245
Reputation: 2576
First answer certainly works, but a slightly more performant example would be:
select top 1 null from users where email = @email
on large or poorly-indexed tables.
Upvotes: 0
Reputation: 2886
select count(*) from users where email = @email
(int)executescalar > 0 == dupe
Upvotes: 4