创建像A1一样的表A2 [英] CREATE TABLE LIKE A1 as A2
本文介绍了创建像A1一样的表A2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个具有旧表属性且没有重复项的新表.我想做这样的事情:
I want to create a new table with properties of an old table and without duplicates. I want to do something like this:
CREATE TABLE New_Users LIKE Old_Users,
AS
(SELECT * FROM Old_Users GROUP BY ID) ;
但是以上方法不起作用.有人可以对其进行修改以使其起作用吗?
But the above is not working. Can anybody modify it to work?
推荐答案
您的尝试还不错.您必须使用LIKE
做到这一点.
Your attempt wasn't that bad. You have to do it with LIKE
, yes.
在手册中说:>
使用LIKE根据另一个的定义创建一个空表 表,包括在 原始表.
Use LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table.
所以您这样做:
CREATE TABLE New_Users LIKE Old_Users;
然后您插入
INSERT INTO New_Users SELECT * FROM Old_Users GROUP BY ID;
但是您不能一口气做到这一点.
But you can not do it in one statement.
这篇关于创建像A1一样的表A2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文