View or Temporary Table - which to use in MS SQL Server?

后端 未结 5 1278
礼貌的吻别
礼貌的吻别 2020-12-08 01:55

I have a problem to decide whether to use a view or a temp table.

I have a stored procedure that i call from program. In that SP i store the result of a long query i

5条回答
  •  暖寄归人
    2020-12-08 02:33

    In general I would use a temporary table when I want to refer multiple times to the same table within a stored procedure, and a view when I want to use the table across different stored procedures.

    A view does not persist the data (in principle): each time you reference the view SQL uses the logic from the view to access the original table. So you would not want to build a view on a view on a view, or use multiple references to a view that has complex logic.

提交回复
热议问题