I have a table :
[sch].[Parent]
(
ID Identity [INT] (PK),
Name VARCHAR(100),
Email VARCHAR(250),
Active TINYINT,
InsertedBy VARCHAR(100),
InsertedDTM DATETIME,
UpdatedBy VARCHAR(100),
UpdatedDTM DATETIME,
)
This table has PK on the ID
column and a UNIQUE NONCLUSTERED CONSTRAINT on Name
.
When I query a normal SQL without a WHERE
clause:
SELECT ID, Name
FROM sch.Parent
This query uses a Index Scan and this is the case when I use a INNER JOIN
with another CHILD table which has an FK in another table
What covering index should I use so that there is Index Seek in case of normal query and INNER JOIN with another table as well?
SELECT
b.Id AS 'ParentsChildId'
, b.[Name] AS 'ParentsChildName'
, a.Id AS 'ParentId'
, a.[Name] AS 'ParentName'
FROM
[sch].[ParentsChild] b
INNER JOIN
[sch].[Parent] a
ON a.Id = b.Id
WHERE
a.Active = 1 AND b.Active = 1