zoukankan      html  css  js  c++  java
  • 每日练习

    DDL(date definition language)数据库定义语言
      create

      scott@TEST>create table t1 ( id number(8), name varchar2(5), sex char(1),year date );  //创建一个新表

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

      scott@TEST>alter table t1 add(sal2 as (sal*2));  //增加一个虚拟列,11g中新增加的特性

      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;  //如果只给一个列起别名,则在相对应的列后起别名

      scott@TEST>create global temporary table temp01 as select * from emp;  //创建一个事务级临时表,这个表中的数据只要事务一结束,数据就会清除,其他用户看不见

      scott@TEST>create global temporary table temp02 on commit preserve rows as select * 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
      日期格式敏感
      字符串得加单引号,同时大小写敏感
      insert
     

      scott@TEST>insert into t3 values (1,'m',to_date('090909','mmddrr'));  //不指定插入的列,那就都要插入 

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

      scott@TEST>insert into t1 select * from emp;  //子查询插入全部列

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

      update
     

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

      scott@TEST>update t1 set a3=(select a3 from t1 where a1='ALLEN') where a1='SMITH';  //子查询插入

      scott@TEST>update t1 set loc=(select loc from dept where dept.deptno=t1.deptno);  //子查询所有列

      delete
      
      scott@TEST>delete t1 where ename='SMITH';  //删除指定的行
      scott@TEST>delete t1;  //删除表中的数据
      scott@TEST>truncate table t1;  //删除表中的数据
      
     
      
    DQL(date query language)数据库查询语言
    select
     
    DCL(date control language)数据库控制语言
    grant
    deny
    revoke
  • 相关阅读:
    Android OpenGL ES 2.0 (四) 灯光perfragment lighting
    Android OpenGL ES 2.0 (五) 添加材质
    冒泡排序函数
    javascript object 转换为 json格式 toJSONString
    Liunx CentOS 下载地址
    jquery 图片切换特效 鼠标点击左右按钮焦点图切换滚动
    javascript 解析csv 的function
    mysql Innodb Shutdown completed; log sequence number解决办法
    Centos 添加 yum
    javascript 键值转换
  • 原文地址:https://www.cnblogs.com/sangmu/p/6804255.html
Copyright © 2011-2022 走看看