CREATE TABLE new_tbl_name SELECT * FROM old_tbl_name / INSERT INTO new_tbl_name SELECT * FROM old_tbl_name



DESCRIBE PRODUCTS_TBL;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| PROD_ID   | varchar(10)  | NO   | PRI | NULL    |       |
| PROD_DESC | varchar(40)  | NO   |     | NULL    |       |
| COST      | decimal(6,2) | NO   |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
SELECT * FROM PRODUCTS_TBL;
+---------+-------------------------+-------+
| PROD_ID | PROD_DESC               | COST  |
+---------+-------------------------+-------+
| 11235   | WITCH COSTUME           | 29.99 |
| 119     | ASSORTED MASKS          |  4.95 |
| 13      | FALSE PARAFFIN TEETH    |  1.10 |
| 15      | ASSORTED COSTUMES       | 10.00 |
| 222     | PLASTIC PUMPKIN 18 INCH |  7.75 |
| 6       | PUMPKIN CANDY           |  1.45 |
| 87      | PLASTIC SPIDERS         |  1.05 |
| 9       | CANDY CORN              |  1.35 |
| 90      | LIGHTED LANTERNS        | 14.50 |
+---------+-------------------------+-------+
CREATE TABLE PRODUCTS_TMP SELECT * FROM PRODUCTS_TBL;
DESCRIBE PRODUCTS_TMP;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| PROD_ID   | varchar(10)  | NO   |     | NULL    |       |
| PROD_DESC | varchar(40)  | NO   |     | NULL    |       |
| COST      | decimal(6,2) | NO   |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
SELECT * FROM PRODUCTS_TMP;
+---------+-------------------------+-------+
| PROD_ID | PROD_DESC               | COST  |
+---------+-------------------------+-------+
| 11235   | WITCH COSTUME           | 29.99 |
| 119     | ASSORTED MASKS          |  4.95 |
| 13      | FALSE PARAFFIN TEETH    |  1.10 |
| 15      | ASSORTED COSTUMES       | 10.00 |
| 222     | PLASTIC PUMPKIN 18 INCH |  7.75 |
| 6       | PUMPKIN CANDY           |  1.45 |
| 87      | PLASTIC SPIDERS         |  1.05 |
| 9       | CANDY CORN              |  1.35 |
| 90      | LIGHTED LANTERNS        | 14.50 |
+---------+-------------------------+-------+
INSERT INTO PRODUCTS_TMP SELECT * FROM PRODUCTS_TBL;

SELECT * FROM PRODUCTS_TMP;
+---------+-------------------------+-------+
| PROD_ID | PROD_DESC               | COST  |
+---------+-------------------------+-------+
| 11235   | WITCH COSTUME           | 29.99 |
| 119     | ASSORTED MASKS          |  4.95 |
| 13      | FALSE PARAFFIN TEETH    |  1.10 |
| 15      | ASSORTED COSTUMES       | 10.00 |
| 222     | PLASTIC PUMPKIN 18 INCH |  7.75 |
| 6       | PUMPKIN CANDY           |  1.45 |
| 87      | PLASTIC SPIDERS         |  1.05 |
| 9       | CANDY CORN              |  1.35 |
| 90      | LIGHTED LANTERNS        | 14.50 |
| 11235   | WITCH COSTUME           | 29.99 |
| 119     | ASSORTED MASKS          |  4.95 |
| 13      | FALSE PARAFFIN TEETH    |  1.10 |
| 15      | ASSORTED COSTUMES       | 10.00 |
| 222     | PLASTIC PUMPKIN 18 INCH |  7.75 |
| 6       | PUMPKIN CANDY           |  1.45 |
| 87      | PLASTIC SPIDERS         |  1.05 |
| 9       | CANDY CORN              |  1.35 |
| 90      | LIGHTED LANTERNS        | 14.50 |
+---------+-------------------------+-------+
时间: 2024-11-12 03:03:29

CREATE TABLE new_tbl_name SELECT * FROM old_tbl_name / INSERT INTO new_tbl_name SELECT * FROM old_tbl_name的相关文章

【SQL篇章--CREATE TABLE】

[SQL篇章][SQL语句梳理 :--基于MySQL5.6][已梳理:CREATE TABLE][会坚持完善] SQL : 1. Data Definition Statements: 1.3 CREATE TABLE 格式:3种建表语句 1.简单SQL表明结构: CREATE TABLE t7(id INT ,NAME VARCHAR(20), PRIMARY KEY(`id`)) ENGINE=INNODB; 格式: CREATE [TEMPORARY] TABLE [IF NOT EXIS

CREATE TABLE常用命令

CREATE TABLE students( stuID INTEGER NOT NULL , stuname char(30) not null, sex int NOT NULL ); CREATE TABLE students( stuID INTEGER NOT NULL , stuname char(30) not null, sex int NOT NULL, PRIMARY KEY (stuID) ); CREATE TABLE students( stuID INTEGER NO

oracle数据库【表复制】insert into select from跟create table as select * from 两种表复制语句区别

create table  as select * from和insert into select from两种表复制语句区别 [sql] view plain copy create table targer_table as select * from source_table insert into target_table(column1,column2) select column1,column2 from source_table 以上两句都是将源表source_table的记录插

create table xxx as select 与 create table xxx like

create table xxx as select xxx,创建新表,没有原表的完整约束,会把原表的数据拷贝一份,如下:mysql> desc stu;+------------+--------------+------+-----+---------+----------------+| Field      | Type         | Null | Key | Default | Extra          |+------------+--------------+------

insert table 和create table as 区别

insert  into  table1(columns1,columns2) select  columns1,columns2  from  table2; 从table2中查询的结果插入到table1中,前提是table1和table2已经存在; oracle中不支持 select columns1  into  table2   from   table1; 其语法为 create.  as..select,有以下三种方式: 1. create table table1 as selec

CREATE TABLE 表名 AS SELECT 语句

1.新表不存在复制表结构即数据到新表 ? 1 2 create table new_table select * from old_talbe; 这种方法会将old_table中所有的内容都拷贝过来,用这种方法需要注意,new_table中没有了old_table中的primary key,Extra,auto_increment等属性,需要自己手动加,具体参看后面的修改表即字段属性.只复制表结构到新表 ? 1 2 3 4 5 6 # 第一种方法,和上面类似,只是数据记录为空,即给一个false

create table b1 as select * from b建表锁表测试

A: create table a1 like a; insert into a1 as select * from a; B: create table b1 as select * from b; 测试AB两种建表语句对原始表的影响.其中a.b的数据量均为300000 rows. 如果使用A种方式建表,insert过程可能会堵塞DML操作(根据innodb mvcc原理) 如果使用B中方式建表,此建表过程全程锁表: 建议:生产环境使用A种方式建备份表:

sqlserver不能直接create table as select

sqlserver不能直接create table as select 在sqlserver 下想复制一张表的,想到oracle下直接create table xxx as select * from ....即可.但是结果却是错误的,baidu一下发现.sqlserver的语法是 : select * into tablenew from tableold Insert into select 与create table as的性能测试及create table 2013-10-05 09:5

create table like 和create table select 比较

语法: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name     [(create_definition,...)]     [table_options] [select_statement]   CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name     [(] LIKE old_tbl_name [)]; 测试过程: 原数据表: mysql> show create table test_or