• ddl dml dcl


    DCL数据控制语言

    创建临时表空间

    create temporary tablespace user_temp   

    tempfile 'E:/oracle/product/10.1.0/oradata/orcl/user_temp.dbf'  

    size 50m   

    autoextend on   

    next 32m maxsize 2048m   

    extent management local;

    创建用户表空间

    CREATE TABLESPACE tbs_sns_idx
    LOGGING
    DATAFILE 
    'E:/oracle/product/10.1.0/oradata/orcl/tbs_sns_idx.dbf' 
    SIZE 32M 
    AUTOEXTEND 
    ON 
    NEXT 32M MAXSIZE 2048M
    EXTENT MANAGEMENT LOCAL;

    创建用户

    create user 用户名 identified by 密码;

    授权

    grant 权限1,权限2,... to 用户名

    范例:将创建session的权限给test用户

    grant create session to test;

    实际上一个新的用户所有的权限都要分别赋予,如果现在假设要想把多个权限一次性赋予一个用户,则可以将这些权限定义成一组角色。

    在Oracle中提供两个主要角色:connect,resource,可以直接把这2个角色赋予test用户。

    范例:

    grant connect,resource to test;

    可在创建用户的同时指定表空间[不指定的话,默认为USERS这个表空间]

    create user 用户名 identified by 密码 default tablespace tbs_sns_idx TEMPORARY TABLESPACE user_temp;

    查看用户表空间使用情况

    select username,default_tablespace from dba_users;

    修改用户的密码

    alter user 用户名 identifiyed by 新的密码;

    在一般的系统中,在用户第一次登陆的时候可以修改密码,要想完成此功能,可以手工让一个密码失效,格式如下:

    alter user 用户名 password expire;

    则用户第一次登陆时会有个提示框修改密码。

    锁住用户

    alter user 用户名 account lock;

    解锁用户

    alter user 用户名 account unlock;

    给test用户查询与删除scott用户的emp表的权利

    grant select,delete on scott.emp to test;

    回收权限

    revoke 权限 on 用户.表名 from 用户;

    范例:回收test用户的select及delete权限

    revoke select,delete on scott.emp from test;

    DDL数据定义语言

    创建表

    create table person(

        pid         varchar2(18),

        name     varchar2(200),

        age        number(3),

        birthday date,

        sex         varchar(2) default'男'

    );

    增加address字段

    alter table person add (address varchar(200) default '暂无地址')

    修改name字段

    alter table person modify (name varchar2(20) default '无名氏')

    删除表

    drop table person

    截断表[清空一张表的数据,可立即释放资源,无法回滚。]

    truncate table person

    创建主键约束,非空约束,唯一约束,检查约束

    create table person(

        pid          varchar2(18),

        name      varchar2(200) unique not null,

        age         number(3) not null,

        birthday  date,

        sex          varchar2(2) default'男',

        constraint person_pid_pk primary key(pid),

        constraint person_name_uk unique(name),

        constraint person_age_ck check(age between 0 and 150),

        constraint person_sex_ck check(sex in ('男','女'))

    );

    创建外键约束

    create table book(

        bid        number,

        bname  varchar2(30),

        bprice   number(5,2),

        pid        varchar2(18),

        constraint book_bid_pk primary key(bid),

        constraint person_book_pid_fk foreign key(pid) references person(pid) [on delete cascade]

    );

    如果是表创建完后再添加约束

    alter table person add constraint person_pid_pk primary key(pid);

    alter table person add constraint person_name_uk unique(name);

    alter table person add constraint person_age_ck check(age between 0 and 150);

    alter table person add constraint person_sex_ck check(sex in ('男','女'));

    alter table book add constraint book_bid_pk primary key(bid);

    alter table book add constraint person_book_pid_fk foreign key(pid) references person(pid) on delete cascade;

    删除约束

    alter table person drop constraint 约束名;

    创建视图

    create or replace view 视图名 as 子查询 [with read only]

    create or replace view empv20 as select empno,ename,job,hiredate from emp where deptno = 20;

    删除视图

    drop view empv20

    创建序列

    create sequence 序列名

    [increment by n][start with n]

    [{maxvalue n|nomaxvalue}]

    [{minvalue n|nominvalue}]

    [{cycle|nocycle}]

    [{cache n|nocache}];

    nextval:取得序列的下一个值

    currval:取得序列的当前值

    create sequence seq_pid;

    insert into person(pid) values(seq_pid.nextval);

     同义词

    create synonym emp from scott.emp;

    sys用户访问scott下的emp表:

    select * from scott.emp;

    创建同义词后:

    select * from emp;即可

    删除同义词

    drop synonym emp;

    DML数据操作语言

    主要是SQL结构化查询语言及INSERT,UPDATE,DELETE的操作

    SQLPLUSW基本命令

    设置行显示长度:set linesize 长度

    设置页显示行数:set pagesize 行数

    ed,@,/ 

    conn 用户名/密码 [as sysdba]

    show user

    数据库的备份与恢复

    exp imp命令的使用

    数据库设计三范式

    第一范式:各属性只包含原子值,不可再分

    第二范式:没有部分函数依赖

    第三范式:没有传递函数依赖

    修改Oracle的8080端口

    1. call dbms_xdb.cfg_update(updateXML(dbms_xdb.cfg_get(),'/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()',9000))  
  • 相关阅读:
    Apple的App Analytics统计平台你必须知道的Q&A整理与翻译
    WWDC2014总结---For产品经理们
    AppStore占坑注意事项
    Mac上的终端(Terminal)启动缓慢
    iOS推送失败的可能问题汇总
    Mac OS X 10.9 Mavericks安装后,Xcode调试时模拟器黑屏的处理方法
    MySql批处理的小窍门:排行榜类数据生成
    升级OSX 10.9 Mavericks后,会导致Finder始终无响应的一个问题
    拉面馆中的移动互联网——无线KPI探讨
    Weak is not weak,Strong is not strong
  • 原文地址:https://www.cnblogs.com/klxll/p/3168804.html
Copyright © 2020-2023  润新知