ddl dml dcl
DCL數(shù)據(jù)控制語言
創(chuàng)建臨時(shí)表空間
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;
創(chuàng)建用戶表空間
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;
創(chuàng)建用戶
create user?用戶名 identified by 密碼;
授權(quán)
grant 權(quán)限1,權(quán)限2,... to 用戶名
范例:將創(chuàng)建session的權(quán)限給test用戶
grant create session to test;
實(shí)際上一個(gè)新的用戶所有的權(quán)限都要分別賦予,如果現(xiàn)在假設(shè)要想把多個(gè)權(quán)限一次性賦予一個(gè)用戶,則可以將這些權(quán)限定義成一組角色。
在Oracle中提供兩個(gè)主要角色:connect,resource,可以直接把這2個(gè)角色賦予test用戶。
范例:
grant connect,resource to test;
可在創(chuàng)建用戶的同時(shí)指定表空間[不指定的話,默認(rèn)為USERS這個(gè)表空間]
create?user?用戶名?identified?by?密碼?default?tablespace?tbs_sns_idx?TEMPORARY?TABLESPACE?user_temp;
?
查看用戶表空間使用情況
select username,default_tablespace from dba_users;
修改用戶的密碼
alter user?用戶名 identifiyed by 新的密碼;
在一般的系統(tǒng)中,在用戶第一次登陸的時(shí)候可以修改密碼,要想完成此功能,可以手工讓一個(gè)密碼失效,格式如下:
alter user 用戶名 password expire;
則用戶第一次登陸時(shí)會(huì)有個(gè)提示框修改密碼。
鎖住用戶
alter user 用戶名 account lock;
解鎖用戶
alter user 用戶名 account unlock;
給test用戶查詢與刪除scott用戶的emp表的權(quán)利
grant select,delete on scott.emp to test;
回收權(quán)限
revoke 權(quán)限 on 用戶.表名 from 用戶;
范例:回收test用戶的select及delete權(quán)限
revoke select,delete on scott.emp from test;
DDL數(shù)據(jù)定義語言
創(chuàng)建表
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
截?cái)啾韀清空一張表的數(shù)據(jù),可立即釋放資源,無法回滾。]
truncate table person
創(chuàng)建主鍵約束,非空約束,唯一約束,檢查約束
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 ('男','女'))
);
創(chuàng)建外鍵約束
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]
);
如果是表創(chuàng)建完后再添加約束
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 約束名;
創(chuàng)建視圖
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
創(chuàng)建序列
create sequence 序列名
[increment by n][start with n]
[{maxvalue n|nomaxvalue}]
[{minvalue n|nominvalue}]
[{cycle|nocycle}]
[{cache n|nocache}];
nextval:取得序列的下一個(gè)值
currval:取得序列的當(dāng)前值
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;
創(chuàng)建同義詞后:
select * from emp;即可
刪除同義詞
drop synonym emp;
DML數(shù)據(jù)操作語言
主要是SQL結(jié)構(gòu)化查詢語言及INSERT,UPDATE,DELETE的操作
SQLPLUSW基本命令
設(shè)置行顯示長度:set linesize 長度
設(shè)置頁顯示行數(shù):set pagesize 行數(shù)
ed,@,/?
conn 用戶名/密碼 [as sysdba]
show user
數(shù)據(jù)庫的備份與恢復(fù)
exp imp命令的使用
數(shù)據(jù)庫設(shè)計(jì)三范式
第一范式:各屬性只包含原子值,不可再分
第二范式:沒有部分函數(shù)依賴
第三范式:沒有傳遞函數(shù)依賴
?
修改Oracle的8080端口
?
轉(zhuǎn)載于:https://www.cnblogs.com/klxll/p/3168804.html
總結(jié)
以上是生活随笔為你收集整理的ddl dml dcl的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 软件测试的艺术
- 下一篇: R语言和Rstudio的介绍和安装