如何在SQL Server中删除表变量?我什至应该这样做吗? [英] How do I drop table variables in SQL-Server? Should I even do this?

查看:184
本文介绍了如何在SQL Server中删除表变量?我什至应该这样做吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在脚本中有一个表变量(不是存储过程).两个问题:

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

  1. 如何删除表变量?删除表@varName会显示错误的snytax"错误.
  2. 我应该一直这样做吗?我听说这是个好习惯.这样的小脚本真的有必要吗?

这是我的代码:

Declare @projectList table(
    name varchar(40) NOT NULL);

Insert Into @projectList
Values ('BCR-00021')

Select *
From @projectList

Drop Table @projectList -- does not work

推荐答案

表变量自动是本地变量,并且会自动删除-您不必担心.

Table variables are automatically local and automatically dropped -- you don't have to worry about it.

这篇关于如何在SQL Server中删除表变量?我什至应该这样做吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆