What to replace left join in a view so i can have an indexed view?

后端 未结 5 1375
既然无缘
既然无缘 2020-12-31 00:43

I have normalized tables in a database and to denormalize it, I created a view out of two tables. When I tried to create a clustered index on the view, it wouldn\'t let me,

5条回答
  •  抹茶落季
    2020-12-31 01:35

    Logically you are making two separate queries. 'A LEFT JOIN B' is just shorthand for '(A JOIN B) UNION A'

    The first query is table A inner joined to table B. This gets an indexed view, since this is where all the heavy lifting is done.

    The second query is just table A where any of the join columns are null. Make a view that produces the same output columns as the first query and pads them with nulls.

    Just union the two results before returning them. No need for a workaround.

提交回复
热议问题