I am facing here a problem with a SQL statement, which fetches the data from table called News according to category :
News : Id(PK) int, Title string, Subject string, Uid int, Cid int.
SELECT Id, Subject, Uid, Title FROM News WHERE Uid = @Uid
This statement operates slowly comparing to statement without WHERE since it should go and check every single row to ensure if it is accomplish the condition.
So imagine with me the table News with 10000000 article. What should I do about such a thing?
If the Id column is a primary key that might already be clustered (they are by default), you just need to create a non-clustered index on the Uid column – especially of the Uid column is a uniqueidentifier (GUID) data type.
This can be created by running the following SQL:
CREATE NONCLUSTERED INDEX IX_News_Uid ON News
(
Uid
)