在 SELECT 语句中创建临时表,无需单独的 CREATE TABLE
是否可以从 select 语句创建临时(仅限会话)表,而不使用 create table 语句并指定每个列类型?我知道派生表能够做到这一点,但它们是超临时的(仅限语句),我想重复使用。
如果我不必编写创建表命令并保持列列表和类型列表匹配,则会节省时间。
Is it possible to create a temporary (session only) table from a select statement without using a create table statement and specifying each column type? I know derived tables are capable of this, but those are super-temporary (statement-only) and I want to re-use.
It would save time if I did not have to write up a create table command and keep the column list and type list matched up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
从 http://dev.mysql.com/ 找到的手册doc/refman/5.7/en/create-table.html
From the manual found at http://dev.mysql.com/doc/refman/5.7/en/create-table.html
除了psparrow的答案之外,如果您需要添加索引到临时表,请执行以下操作:
它也适用于
PRIMARY KEY
In addition to psparrow's answer if you need to add an index to your temporary table do:
It also works with
PRIMARY KEY
使用这个语法:
Use this syntax:
发动机必须在选择之前:
Engine must be before select:
当表包含
BLOB
/TEXT
列时,不支持ENGINE=MEMORY
ENGINE=MEMORY
is not supported when table containsBLOB
/TEXT
columns据我了解,如果您在 phpMyAdmin 等中使用 SELECT 语句,则该语句将在临时表上起作用,但在该 SELECT 之后,临时表将消失。这意味着首先准确设置您想要对其执行的操作,并且在更改数据(删除、更新)的“操作”语句完成之前不要查看任何结果。
As I understand it, a SELECT statement will work on the temporary table if you're using it in something like phpMyAdmin, but following that SELECT, the temporary table will be gone. This means set up exactly what you want to do with it first, and don't view any results till your 'action' statements that change the data (DELETE, UPDATE) are complete.