Is there a need to index the short string code for a faster query?
3
votes
1
answer
102
views
We have a large number of tables for setup forms.
In each form, there is a need to fill in the
Code
and the Description
.
The Code consists of a varchar(10)
datatype.
Now, the thing is, every time a user creates new data or updates the data, there is a need to check whether the Code
conflicts with the others or not.
In LINQ, this code checking is inevitable:
string ExistingCode = "ITEM01";
int ExistingKey = 1;
var recordWithConflictedCode = (from a in db.MyTable
where a.Code == ExistingCode &&
a.Key != ExistingKey).ToList();
if(recordWithConflictedCode.Count >= 1)
return BadRequest("Duplicated Code found");
Now, since this involves a string comparison on every process, I think it makes sense to index the column Code
to make the query faster.
Is this a common practice for you guys?
Asked by zeroflaw
(325 rep)
Jan 20, 2017, 02:45 AM
Last activity: Jan 20, 2017, 05:45 PM
Last activity: Jan 20, 2017, 05:45 PM