开发者

Checking if email address already exists in db

开发者 https://www.devze.com 2023-02-13 18:34 出处:网络
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 ema

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消