Using “AS” in MySQL - not as aliases

柔情痞子 提交于 2019-12-24 01:39:22

问题


I was kinda surprised when I saw following:

CREATE TEMPORARY TABLE X (ID int) AS SELECT NumColumn FROM Table

I have tried to google it but only found using this as alieases. What this use actually is? I feel bit confused since I was stupidly creating temporary table and then fill it by using of insert..

Thank you


回答1:


Its how you create a temporary table and populate it with the results of a select query.

You can see it in the documentation at the very bottom of the CREATE TABLE specification

select_statement:
[IGNORE | REPLACE] [AS] SELECT ... (Some legal select statement)




回答2:


This will create a temporary table for you but just remember that this will not bring along any indexes you had on the original table. For that reason, sometimes it may be better create a complete copy of the table definition using

create table x like y; 

Since this only creates an EMPTY table, you need to also run

insert into x (col1) select col1 from y;



回答3:


CREATE TABLE (table name) AS SELECT * FROM (existing table name);

this command for copy whole table in to another table;



来源:https://stackoverflow.com/questions/2471343/using-as-in-mysql-not-as-aliases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!