How do I drop table variables in SQL-Server? Should I even do this?

前端 未结 7 1939
执笔经年
执笔经年 2020-12-12 18:58

I have a table variable in a script (not a stored procedure). Two questions:

  1. How do I drop the table variable? Drop Table @varName gives an \"Incorrect snyta
7条回答
  •  一向
    一向 (楼主)
    2020-12-12 19:14

    Temp table variable is saved to the temp.db and the scope is limited to the current execution. Hence, unlike dropping a Temp tables e.g drop table #tempTable, we don't have to explicitly drop Temp table variable @tempTableVariable. It is automatically taken care by the sql server.

    drop table @tempTableVariable -- Invalid
    

提交回复
热议问题