Table variable vs Temporary tables

  • When & why should I use table variables instead of temporary tables???

  • A starter for you.

    Variables are designed to hold one value at a time, whereas temporary tables contain rows and rows of data. You could if wanted to, assign a row of data to various variables, but you will only ever have one row of data at a time.

    A temporary table allows you to temporarily keep multiple rows of data that you can play around with before losing the contents.

    Key use of a variable is holding constant values. When updates are required you only have to change the variable, rather than searching and replacing through the code.

    Key use of temporary table is to get some values back, do something with them and then destroy. E.g create a temp table, link it to another table, perform an update...etc, then display the results to user without keeping a permanent table which will use space.

    These are very basic examples. Search this site for some real life examples.


    ------------------------------
    The Users are always right - when I'm not wrong!

  • Note, the question was regarding Table variables, not variables designed to hold single scalar values.

    Try this recent thread on the same subject:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=157332&p=2

     

  • Whoops. Misread completely.


    ------------------------------
    The Users are always right - when I'm not wrong!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply