ORACLE 创建和管理表

来源:互联网 发布:淘宝开旗舰店费用 编辑:程序博客网 时间:2024/05/16 17:18
前奏:DDL: Data Definition Language 数据定义语言;      DDL用于定义数据库的结构,比如创建、修改或删除数据库对象,包括如下SQL语句:       CREATE TABLE:创建数据库表   ALTER  TABLE:更改表结构、添加、删除、修改列长度   DROP TABLE:删除表   CREATE INDEX:在表上建立索引   DROP INDEX:删除索引表是最常见的oracle数据库对象:表:基本的数据存储集合,由行和列组成。select * from user_tables;select * from user_catalog;select * from user_objects;select distinct object_type from user_objects;--创建表create table t_emp(id number(10), name varchar2(20), salary number(10 ,2), hire_date date)select * from t_emp;--依托于其他表创建表(数据也会相应的倒过来)create table t_emp00as select t.employee_id id , t.last_name name ,t.hire_date , t.salary from employees t;--如何不将数据导入create table t_emp01as select t.employee_id id ,t.last_name ,t.hire_date ,t.salary  from employees t where 2=3;select * from t_emp00;select * from t_emp01;--修改表--增加一列alter table t_emp01 add(email varchar2(20));--修改某一列的长度alter table t_emp01modify(email varchar2(25));alter table t_emp01modify(id number(13,2) default 2000);select * from t_emp01;insert into t_emp01(id,last_name,email,hire_date) values (1,'cui','cuigaochong@163.com',to_date(15/08/16,yyyy/mm/dd));--删除一列alter table t_emp01drop column email;--删除表结构 drop table t_emp01;--清空表 数据清空   该操作回滚无效truncate table t_emp00;--delete数据是可回滚的,delete from t_emp02;rollback;select * from t_emp02;--更改表名rename t_emp02 to t_emp03;select * from t_emp03;DDl语句执行后 都不能回滚

1 0
原创粉丝点击