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

每日练习

时间:2017-05-22 00:12:59      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:添加   flash   odi   重命名   字符   comment   cot   每日   insert   

DDL(date definition language)数据库定义语言
  create
scott@TEST>create table t1 (  //创建一个表t1
  2  id number(8),
  3  name varchar2(5),
  4  sex char(1),
  5  year date );

scott@TEST>create table t2 as select * from emp;  //创建一个表,表结构和数据和表emp完全一样

scott@TEST>create table t3 as select ename,job,sal from emp where 1=2;  //创建一个表,表结构和表emp一样,但是不要数据

scott@TEST>create table t1(a1,a2,a3) as select ename,job,sal from emp;  //可以同时给列起别名,但是别名得和列相对应

scott@TEST>create table t2 as select ename a1,job,sal from emp;  //如果只给一个列起别名,则在相对应的列后起别名

  alter
scott@TEST>alter table t1 modify (id number(10));  //修改一个列的类型,如果没有数据可以修改。如果有数据,就只能增大数据字节

scott@TEST>alter table t1 rename column id to ida;  //给一个列重命名

scott@TEST>rename t1 to t11;  //给一个表重命名

scott@TEST>alter table t1 add (id number(10),sal number(5));  //新增加两列数据

scott@TEST>alter table t1 drop column sal;  //删除一个列

scott@TEST>alter table t1 drop (year,sex);  //删除两列,这个地方也可以删除一列,在括号里写一个列名也可以

scott@TEST>comment on table t2 is abcd;  //给一个表添加一个备注

scott@TEST>select comments from user_tab_comments where table_name=T2;  //查看表的备注
scott@TEST>comment on column t2.sal is money;  //给一个列添加一个备注
scott@TEST>select comments from user_col_comments where table_name=T2 and column_name=SAL; //查看列的备注

  drop

scott@TEST>drop table t1;  //删除表t1
scott@TEST>show recyclebin; //显示回收站
scott@TEST>purge table t1; //清空回收站中指定的表 scott@TEST>drop table t2 purge; //直接删除表,不放入回收站中 scott@TEST>flashback table t3 to before drop //恢复回收站中指定的表 scott@TEST>purge recyclebin; //清空回收站中全部内容 
 
DML(date manipulation language)数据操作语言
  insert
  分为隐式插入和显式插入null
  日期格式敏感
  字符串得加单引号,同时大小写敏感
scott@TEST>insert into t3 values (1,m,to_date(090909,mmddrr));  //不指定插入的列,那就都要插入

scott@TEST>insert into t3(id) values (1);  //指定要插入的列,要注意有没有不允许为空的列

scott@TEST>insert into t2 (ename)  select ename from emp;  //子查询插入列

  update
scott@TEST>update t1 set a3=900 where a1=SMITH;  //更新数据

1 row updated.

scott@TEST>update t1 set a3=(select a3 from t1 where a1=ALLEN) where a1=SMITH;

1 row updated.
  delete
scott@TEST>delete t1 where a1=SMITH;  //删除一行数据

scott@TEST>delete t1 ;  //删除一个表数据

13 rows deleted.
DQL(date query language)数据库查询语言
select
 
DCL(date control language)数据库控制语言
grant
deny
revoke

每日练习

标签:添加   flash   odi   重命名   字符   comment   cot   每日   insert   

原文地址:http://www.cnblogs.com/sangmu/p/6804255.html

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