table variable

  • I have a table variable that I want to reuse like a temp table. How do I clear out the data and reset the identity seed so I can use it in a while loop?

    I would like to use something like Truncate table, but of course that is not an option. is there a easy way to clear the variable from memory?

  • You should just use a temp table and truncate it.

    Are you sure what you are doing requires a loop?

  • It is just a one time script. I am surprised there is no way to un declare it and declare it again. Thanks

  • Why not just declare a second table variable? It's a trivial cut-and-paste and will start all over again with the identity values. If you want to clear memory/disk space you can just delete @tableVar1 and then use @tableVar2 for your subsequent operation. Or not. 😀

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • JKSQL (12/3/2008)


    It is just a one time script. I am surprised there is no way to un declare it and declare it again. Thanks

    Can you un-declare and re-declare any other type of variable? All variable's scope, lifetime and visibility are fixed to the batch/procedure that they are declared in.

    If you want to dynamically drop and recreate something then you want an object, not a variable. One object that seems like it would be perfrect for you is a temporary table.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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