I'm trying开发者_如何学JAVA 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
select count(*) from users where email = @email
(int)executescalar > 0 == dupe
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.
精彩评论