MySQL:什么是临时表?
如以下语句所示,临时表的用途是什么?它和普通桌子有什么不同?
CREATE TEMPORARY TABLE tmptable
SELECT A.* FROM batchinfo_2009 AS A, calibration_2009 AS B
WHERE A.reporttime LIKE '%2010%'
AND A.rowid = B.rowid;
What is the purpose of a temporary table like in the following statement? How is it different than a regular table?
CREATE TEMPORARY TABLE tmptable
SELECT A.* FROM batchinfo_2009 AS A, calibration_2009 AS B
WHERE A.reporttime LIKE '%2010%'
AND A.rowid = B.rowid;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
临时表仅在您与服务器的会话期间保留。一旦连接因任何原因被切断,该表就会自动删除。它们也仅对当前用户可见,因此多个用户可以使用相同的临时表名称而不会发生冲突。
Temp tables are kept only for the duration of your session with the sever. Once the connection's severed for any reason, the table's automatically dropped. They're also only visible to the current user, so multiple users can use the same temporary table name without conflict.
当连接关闭时,临时表将不再存在。因此,它的目的是在使用之前保存必须处理的临时结果集。
Temporary table ceases to exist when connection is closed. So, its purpose is for instance to hold temporary result set that has to be worked on, before it will be used.
临时表主要用于存储需要进一步处理的查询结果,例如,如果结果需要再次查询或细化,或者应用程序将在不同场合使用结果。通常,存储在临时数据库中的数据包含来自多个常规表的信息(如您的示例中所示)。
当当前数据库会话终止时,临时表将自动删除。
Temporary tables are mostly used to store query results that need further processing, for instance if the result needs to be queried or refined again or is going to be used at different occasions by your application. Usually the data stored in a temporary database contains information from several regular tables (like in your example).
Temporary tables are deleted automatically when the current database session is terminated.
对临时表的支持是为了允许基于集合的 4GL 中的程序范例,要么是因为编码人员尚未将其 3GL 思维模式切换到新范例,要么是为了解决性能或语法问题(感知或其他问题)。
Support for temporary tables exists to allow procedural paradigms in a set-based 4GL, either because the coder has not switched their 3GL mindset to the new paradigm or to work around a performance or syntax issue (perceived or otherwise).