1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[SQL] What Columns Should I Index to Improve Performance in SQL

Discussão em 'Outras Linguagens' iniciado por Stack, Julho 22, 2021.

  1. Stack

    Stack Membro Participativo

    On my query I have a temp table of keys that will be joined to multiple tables later on. I want to create an index on my temp table to improve performance, cause it takes a couple of minutes for my query to run.

    SELECT DISTINCT k.Id, k.Name, a.Address, a.City, a.State, a.Zip, p.Phone, p.Fax, ...
    FROM #tempKeys k
    INNER JOIN dbo.Address a
    ON a.AddrId = k.AddrId
    INNER JOIN dbo.Phone p
    ON p.PhoneId = a.PhoneId
    ...


    My question is should I create an index for each column that is being joined to a table separately

    CREATE NONCLUSTERED INDEX ... (Addr.Id ASC)
    CREATE NONCLUSTERED INDEX ... (PhoneId ASC)


    or can I create one index that includes all columns being joined

    CREATE NONCLUSTERED INDEX ... (Addr.Id ASC, PhoneId ASC)


    Also, are there other ways I can improve performance on this scenario?

    Continue reading...

Compartilhe esta Página