开发者

Checking if email address already exists in db

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜