• blandry (7/17/2008)


    Great article, and thanks for it - but under the heading of "the more I learn the less I know"...

    Is there really any difference or advantage between Temp Tables and Table variables? If there is not enough cache on hand and both will eventually hit TempDB - is the only advantage that Table variables dont hit it explicitly to start?

    I agree with Blandry, this was a great article.

    As to advantages and disadvantages, as many people have said sometimes one is better than the other. The ability to create indexes, add columns and use other "Alter Table" commands on a table variable can be handy in certain occasions.

    I personally prefer to use table variables in most situations[/i] because they only exist in the context of the currently running script whereas temp tables exist within your session. This can make a big difference about whether or not I need to worry about dropping temp tables and checking for the existence of temp tables if I am debugging and script and therefore running it over and over with small changes.

    ---
    Timothy A Wiseman
    SQL Blog: http://timothyawiseman.wordpress.com/