美文网首页oracle经验之谈
12、DDL改变表结构操作

12、DDL改变表结构操作

作者: 小母牛不生产奶 | 来源:发表于2018-10-21 12:44 被阅读0次

    创建表

    Create table student( Sid number(10), Snamevarchar2(10) ) tablespace tt; 

    以上 tablespace 不是必须的。默认不写,则创建在登录的用户所在的表空间上


    使用子查询创建表

    create table myemp as select * from emp;

    create table myemp as select * from empwhere deptno=10;

    create table myemp as select * from emp1=2;


    添加字段

    Alter table student add age number(5);


    修改字段

    Alter table student modify age number(10);

    alter table table2 rename column result toresult2;


    删除字段

    Alter table student drop column age;


    清空表数据

    Truncate table student; 

    正常情况下删除数据,如果发现删除错了,则可以通过 rollback 回滚。如果使用了截断表,则表示所有的数据不可恢复了.所以速度很快(更详细的说明可查看 Oracle 体系结构)


    删除表

    Drop table student;


    重命名表

    Rename student to student1; 

    相关文章

      网友评论

        本文标题:12、DDL改变表结构操作

        本文链接:https://www.haomeiwen.com/subject/jokbzftx.html