Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
创建临时表有两种方法。
这将创建表并从 PHYSICALTABLE 插入数据;
另一种方法是使用 CREATE TABLE 方法;
连接关闭后,或者在临时表上使用 DROP TABLE 命令时,服务器将删除临时表。 除非您使用全局临时表(通过在表名中添加 ##),否则每个连接只能访问自己的临时表。 我读过临时表会导致大表的性能损失,所以我通常只使用临时表来合并两个表,然后对这两个表进行分组+求和。
There are two ways to create temp table.
This one will create the table and insert data from PHYSICALTABLE;
The other way is to use CREATE TABLE method;
Temp tables will be removed by server once the connection is closed, or when you use DROP TABLE command on them. Unless you use global temp tables (By adding ## into table name), every connection only has access to their own temp tables. I had read temp tables causes performance loss on big tables, so I usually only use temp tables to UNION two tables then group by+SUM those two.
这是创建临时表并从中进行选择的快速 SQL 语句
Here is a quick bit of SQL to create a temp table and select from it
以下指南似乎是一个很好的起点,可以了解有关临时表(和表变量)的详细信息,包括生命周期、共享等:
SQL Server 临时表真的有必要吗? 还考虑出于性能原因使用临时表。
将它们与“普通”表进行比较,我想说最大的区别本质上是普通表保留在数据库中,因此每当您需要存储正在使用的数据时就应该使用普通表,而如果只是在数据库中工作则应该使用临时表。查询/存储过程等的上下文...
The following guide appears pretty good place to start for detailed information about temporary tables (& table variables) including life-time, sharing etc.:
Are SQL Server Temp Tables Really Necessary? also looks at using temporary tables for performance reasons.
Comparing them to 'normal' tables i would say the biggest differences is essentially that normal tables persist in the database and thus should be used whenever you need to store the data you are working with, wheras temporary tables should be used if just working within the context of a query/stored procedure etc...