七、Oracle中DDL改变表结构操作

こ雲淡風輕ζ 提交于 2020-01-31 17:46:39

目录

7.1. 创建表

7.2. 使用子查询创建表

7.3. 添加字段

7.4. 修改字段

7.5. 删除字段

7.6. 清空表数据

7.7. 删除表

7.8. 重命名表


7.1. 创建表

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

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


7.2. 使用子查询创建表

create table myemp as select * from emp;

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

create table myemp as select * from emp1=2;


7.3. 添加字段

Alter table student add age number(5);


7.4. 修改字段

Alter table student modify age number(10);

alter table table2 rename column result toresult2;


7.5. 删除字段

Alter table student drop column age;


7.6. 清空表数据

Truncate table student; 

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


7.7. 删除表

Drop table student;


7.8. 重命名表

Rename student to student1; 

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