Views Vs Temporary Table or Temporary Variables in SQL server
I want to understand performance merits/demerits in 开发者_Go百科using views instead of temporary tables in stored procedures in SQL Server.
I know the difference between the two (like temporary table can give stale data, etc.) but I could [not] find any info from performance perspective anywhere.
Views
will not give improved performance unless you have Enterprise edition
and your view can follow the rules for an indexed view
. Views which call other views can cause severe performance issues. Temp tables
do have stale data, but for the purposes of a transaction with multiple actions in a proc that is a generally good thing as all actions are operating against the same set of data. That leads to fewer data integrity problems. Table varaibles
are faster than temp tables
in smaller sets of data generally but temp tables
tend to perform better for the larger sets especially since they can be indexed. As with all performance tuning, there are differences depending on your particular hardware and database design, so if you are concerned about performance (as you should be) then you need to test the various options to see hwat works best for your particular instance.
精彩评论