Interpretation of BoL - table variables

  • G'Day Everyone,

    I am looking for confirmation, and ideally a place in the documentation, that specifically states table variables can or cannot be used as a parameter passed into a stored procedure.  From BoL: "All data types, including text, ntext and image, can be used as a parameter for a stored procedure."  This seems to imply that a table variabel can be used.  However, in several attempts I have not been able to find a syntax that works.

    'nuf said...  Your thoughts?

    Wayne

  • It is not possible to pass a table variable to a SP or UDF. It appears to be a case of the BOL documentation not being kept up to date when Table variables were added in SQL2K.

    It's asked often in the microsoft.public.sqlserver.* newsgroups:

     

    http://www.google.ca/groups?num=100&hl=en&lr=&q=table+variable+parameter+group%3Amicrosoft.public.sqlserver.*

     

  • I don't have BOL to hand as a write this but I am pretty sure that I read that table variables are not allowed in the latest version of BOL.

    I think the last BOL update was in Jan 2004.

    Subjects that have been updated are clearly marked.

  • Thanks PW,

    The link to the google search was the confirmation I was looking for.  Not what I hoped to hear, but the results clearly put the question firmly to rest.

    Thanks for the fast response

    Wayne

  • David, wtf are you doing online here at almost a quarter past ten in the evenings???

    I thought I am the only European who is that crazy after all

    Anyway, I have a good reason: This evening I got nothing better to do with my time. You know why

    To add to the thread: While it is true, that Microsoft greatly introduced table variables I think they now take a different direction. Temp tables are at least equally good as table variables. I use temp tables all around the place.

    ...and BOL isn't that specific as it should be in *many* places.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • FYI this is from the last BOL Update

    CREATE PROCEDURE

    "All data types, except the table data type, can be used as a parameter for a stored procedure."

  • OK, where do you get the latest BOL update?

    There is no "i" in team, but idiot has two.
  • This link should get you there.

     

    http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

  • Ah, Frank.  When you have three kids and your wife works nights the only chance you get to surf the internet is when the kids go to bed.  It is the 3:00am postings that should worry you

    Satellite TV seems to consist of charging you for watching programs you saw for free on BBC 10 years ago plus rubbish that wouldn't have been good enough to be included in schedules when Britain only had three channels.

  • Frank, would you mind elaborating on your commment about temp tables?  I was under the impression that table variables typically incurred less server cost during use.

    Or, are they typically just prefered because they are dropped at the batch level instead of the connection level?

    Thanks

    Ryan

  • Table variables are held in memory and therefore are very fast.  Implicit in this is that they are fairly small tables, otherwise the memory penalty would be detrimental to server performance.

    Temporary tables are physically stored in TEMPDB and can handle far bigger tables.  You can also add indices and primary keys to them.

    There are certain commands you cannot use on a table variable that you can on temporary tables.  I think TRUNCATE is one of them.

    I did do some tests on a recursive routine that had to trace a parent/child relationship between objects and came to the conclussion that in absolute terms there wasn't a fantastic difference in performance in my particular implementation.

    I think one was faster for inserting data and the other was faster for joining data and the strengths and weaknesses of both cancelled each other out for the recursive routine.

  • David -

    American cable is the same dreck - shows that were cancelled years ago rise from the dustbin to "entertain" you again. Who wants to watch 150 channels showing recurring episodes of "Wings" or "Golden Girls"?

    I like the flexibility of table variables, although you cannot use EXEC stored proc to populate them. Oh well.

    Quand on parle du loup, on en voit la queue

  • The following MS KB article has a useful comparison of table variables versus temp tables:

    http://support.microsoft.com/default.aspx?scid=kb;en-us;305977

     

     

  • Do you get the programs that have 15 minutes of content but are 1 hour long?

    I saw one on engineering disasters with a 125mph train crash in Germany and it used virtually every possible combination of phrases for telling us that the train was travelling at 125mph and that it crashed.

    I'm at the stage where I find the adverts are more entertaining, have better background music and are less repetitive.  Unfortunately (or fortunately depending on your view point) European adverts have a high nudity content so a lot of them would be banned in the USA.

  • Glad someone posted that Microsoft link as I couldn't find to save me. The statement about TempDB is incorrect with Tbale Variables see the following.

     

    Q4: Are table variables memory-only structures that are assured better performance as compared to temporary or permanent tables, because they are maintained in a database that resides on the physical disk?

    A4: A table variable is not a memory-only structure. Because a table variable might hold more data than can fit in memory, it has to have a place on disk to store data. Table variables are created in the tempdb database similar to temporary tables. If memory is available, both table variables and temporary tables are created and processed while in memory (data cache).

Viewing 15 posts - 1 through 15 (of 19 total)

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