服务器 频道

oracle学习个人总结

  【IT168 服务器学院】 表空间

  创建表空间

  SQL> create tablespace emp

    2  logging

    3  datafile ''/oracle/oradata/dba/emp.dbf'' size 5M extent

    4  management local;

  增加表空间大小

  SQL> alter tablespace emp

    2  add datafile ''/oracle/oradata/dba/emp_1.dbf'' size 3M;

  删除表空间

  SQL> drop tablespace emp including contents;

  2         

  创建用户

  create user jackylau identified by richie default tablespace emp temporary

  tablespace temp quota 15m on emp password expire;

  授权用户

  grant dba to jackylau with admin option;

  alter user jackylau default role all;

  修改用户密码

  alter user jackylau identified by richie

  表

  创建表

  SQL> create table qq

    2  (name varchar(20),

    3  id number(10),

    4  relation varchar(6),

    5  gender varchar(4)

  6         );

  从其它表中建表

  create table temp as select name,id from qq;

  重新命名一个表名

  rename qq to qqtest

  查看一个表的结构

  desc table_name;

  插入记录

  insert into qq (name,id,relation,gender) values (''宝儿'',''33796776'',''朋友'',''女'');

  insert into qq values (''宝儿'',''33796776'',''朋友'',''女'');

  修改记录

   update qq set name=''apple''

   where id = ''371692320'';

  把id号为371692320的项为name所在的名改为apple

  更改列的字符大小

  alter table qq modify (gender varchar(6));

  增加列

  alter table qq add time date;

  删除列

  alter table qq set unused ("TIME") cascade constraints;(注意TIME要大写)

  删除内容

  truncate table qq drop storage;(截掉,不可恢复)

  查询

  select * from qq;

  select id from qq where id=''18243386'';

  select * from qq where gender=''女'' order by name;

  select * from qq where id like ''%8%'' order by name;

  删除记录

  SQL> delete from qq

    2  where id=''18243386'';

  回滚

  消除上一个COMMIT命令后的所做的全部修改,使得数据库的内容恢复到上一个COMMIT执行后的状态.使用方法是:

  SQL>rollback;

  LINK

  那个字段 LIKE "字符组合"

字符组合 可以是固定字符 与 % 和 _ 的随意组合,其中 % 代表任意长度的任意字符,_ 代表单个字符

  where name like ''jacky___'' 能查到 jackylau 却不能查到 jackylau+where name like ''%acky___'' 能查到 jackylau, abcackylau 却不能查到 jackylausomeword

SQL> edit s<回车>
如果当前目录下不存在s.sql文件,则系统自动生成s.sql文件,
在其中输入“select * from tab;”,存盘退出。
SQL> @s<回车>
创建用户并授权

  SQL> create user 用户1 identified by 密码;

SQL> grant connect,resource to 用户1;

SQL> connect 用户1/密码

SQL> create table 表1(列1 number,列2 date);

SQL> create index 索引1 on 表1(列1);

SQL> drop index 索引1;

SQL> drop table 表1;

  创建视图

Create or replace view testview as select col1,col2,col3 from table_name;

create view test_view as select name,id,gender from qq;

select * from test_view;

create view qqtest as select name,id,relation lation from qq where id>100000000;(并重新命名relation列为lation)

create view qqtest as select name,id,gender from qq where id>100000000 with read only;

创建序列

CREATE SEQUENCE inc_hourdiscount INCREMENT BY 1 START WITH 1    MAXVALUE 1.0E28;

查看数据库

show parameter db_name;

select name from v$database;

如何单独备份一个或多个用户?

  exp system/manager owner=(用户1,用户2,…,用户n) file=导出文件

  如何单独备份一个或多个表?

  exp 用户/密码 tables=(表1,…,表2)

0
相关文章