Question: I have table **Eli** with 1 million records. When I query the following:

```
Select count(*) from Eli where userId ='my_user'

```

It is taking more than 10 mins to give results. I searched web and found better way to optimize the query from `http://dbatipster.blogspot.com/2009/08/get-row-counts-fast.html`.

How do I utilize the the following query into my above query-

```
SELECT OBJECT_NAME(i.id) [Table_Name], i.rowcnt [Row_Count] 
FROM sys.sysindexes i WITH (NOLOCK) 
WHERE i.indid in (0,1) 
ORDER BY i.rowcnt desc

```

Answer: 
Without touching on properly building a table, I would use something like this:

```
SELECT COUNT(userID) FROM Eli (NOLOCK)
WHERE userId ='my_user'

```

The `(NOLOCK)` hint allows you to select from the table without other transactions against the Eli table being committed, meaning you're not waiting for other updates and inserts to complete before returning your results.
> 
> It is taking more than 10 mins to give results
> 
> 
> 

A cound over 1 million rows does not take that long. You bark the wrong tree. Totally. On a comical level - like complaining about the fuel consumption of a car with a broken tank leaking fuel. Seriously.

The only reason you would ever take that long is excessively bad locking - which is what you should fix. 1 million rows is nothing. Even on a 10 year old computer on a slow hard disc from that era it would not take even a minute to do your query. Something is blocking here. Likely other code written by a not competent programmer that is keeping around locks for way longer than it needs, possibly even excessive locks.