码迷,mamicode.com
首页 > 其他好文 > 详细

CREALE TABLE   表名   AS  SELECT .......

时间:2016-09-30 02:11:27      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

1语法:

create table  表名 as select ..........

 

2用处:

是复制表结构和表数据

3例子:
(1*)

SQL> create table tt as select * from dept;

Table created.

SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> select * from tt;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL>

(2*)

SQL> create table ss as select * from dept where deptno=1;

Table created.

SQL> select * from ss;

no rows selected

SQL> select deptno from ss;

no rows selected

SQL> desc ss;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 DEPTNO                                             NUMBER(2)
 DNAME                                              VARCHAR2(14)
 LOC                                                VARCHAR2(13)

SQL>  desc tt;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 DEPTNO                                             NUMBER(2)
 DNAME                                              VARCHAR2(14)
 LOC                                                VARCHAR2(13)

SQL>

4总结:

能复制数据结构和数据  但where条件不成立的时候,只生产表结构。

CREALE TABLE   表名   AS  SELECT .......

标签:

原文地址:http://www.cnblogs.com/material/p/5922357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!