Right now using SQLite i write the below (I may move to either mysql or ms sql)
command.CommandText = "SELECT count(reset_key) user_data WHERE reset_key=@key;";
This works but is there a more optimized or cleaner way?
Right now using SQLite i write the below (I may move to either mysql or ms sql)
command.CommandText = "SELECT count(reset_key) user_data WHERE reset_key=@key;";
This works but is there a more optimized or cleaner way?
That's about the cleanest, most optimized way there is. Make sure that there's an index on reset_key
and it will be very, very fast.
Try
Select Case When Exists (Select * From user_Data
Where reset_key = @key)
Then 1 Else 0 End
SQLite has the support of LIMIT clause. That might help.
EDIT: I don't know the SQLite syntax. But in SQL sense, it would look like
Select 1 From user_Data Where reset_key = @key LIMIT 1
command.CommandText = "SELECT TOP 1 1 FROM user_data WHERE reset_key=@key"
if (commmand.ExecuteScalar() == null)
{
//code for no matches here
}