教材常用代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
----------------------------------第三章-------------------------
共享池:
alter system
set CHARED_POOL_SIZE=32M;
数据高速缓冲区:
alter system
set DB_CACHE_SIZE=48M;
内存缓冲区顾问
1.select id,name,block_size,advice_status from v$db_cache_advice;
2更改状态 on内存cpu
,redy内存,
,off不分配内存不cpu
alter system
set db_cache_advice=off;
查看:
select id,name,block_size,advice_status from v$db_cache_advice;
开启:alter system
set db_cache_advice=on;
获取参数文件的全部参数:
show parameter;
获取sga的相关信息:
show sga;
col name for a20
col value for a25
select name,type,value
from v$parameter
where name='sga_max_size';
---------------------------------------
重做日志写进程:LGWR
数据写进程:DBWR/DBWn
系统监督进程:SMON
进程监督进程:PMON
校验点(checkpoint)进程:
归档日志(ARCH/ARCn)进程(可选);
---------------------------------------
cd D:\oracle_10g\product\10.2.0\db_1\BIN
isqlplusctl start
http://tgh:5560/isqlplus/
http://localhost:5560/isqlplus/
http://tgh:1158/em/console/logon/logon;jsessionid=c0a8e0014869e3f0283047b4a2eb98e9d500cbc5c90
---------------------------------------
静态参数文件: pfile --init.ora /database
动态参数文件:spfile
spool c:\sql\parameter
show parameter
spool off
将数据库设置为限制模式:
select sid,serial#,username,type from v$session;
alter system kill session '7.19';
几种关闭数据库的方式:
shutdown abort --->只有重启数据恢复
shutdown transactional
shutdown immediate
shutdown normal
关闭方式 A I T N
---------------------------------------------------
允许新的连接 no no no no
等待当前所有会话结束 no no no yes
等待当前所有事物结束 no no yes yes
强制检查点和关闭文件 yes yes yes yes
---------------------------------------------------
查看警报文件位置:D:\oracle_10g\product\10.2.0\admin\orcl\bdump
col name for a30
col value for a45
set line 100
select name,value
from v$parameter
where name like '%_dest';
----------------------------------第四章-------------------------
数据字典视图:
user_objects
all_objects
dba_objiects
desc user_objects;
desc all_objects;
desc dba_objects;
col owen for a8
col object_name for a12
col object_type for a10
select owner,object_name,object_id,created,status
from all_objects
where owner='SCOTT';
利用数据字典user_tables查看当前用户下有哪些表:
select table_name
from user_tables;
哪些表有用:
select table_name,owner
from all_tables
where owner not like '%SYS';
user_catalog比user_tables更简单显示拥有哪些表
desc user_catalog;
select * from user_catalog;
user_catalog有个别名cat
select * from cat;
-------------------------
动态性能视图
v$开头
v$fixed_table 或者dictionary查看哪些数据字典
select * from dictionary;
select * from v$fixed_table;
如果想知道数据字典某一列的含义:dic_columns
select * from dict_columns
where table_name='DBA_TABLES'
and column_name='INITIAL_EXTENT';
orcle数据库的名字,创建日期,v$database
select name,created,log_mode,open_mode
from v$database;
计算机主机名,实例名,版本
col host_name for a15
select host_name,instance_name,version
from v$instance;
版本的详细信息:
select * from v$version;
控制文件信息
select * from v$controlfile;
重做日志文件信息:
select group#,members,bytes,status,archived
from v$log;
重做日志文件位置:
col menber for a45
select * from v$logfile;
评估备份和恢复策略并确定归档文件的具体位置
archive log list
数据库有多少表空间以及每个表空间的状态dba_tablespaces
col tablespace_name for a15
select tablespace_name,block_size,status,contents,logging
from dba_tablespaces;
每个表空间存在位置以及文件名字
col file_name for a40
select file_id,file_name,tablespace_name,status,bytes
from dba_data_files;
有多少用户,创建时间
select username,created
from dba_users;
查看控制文件的配置:
select type,record_size,records_total,records_used
from v$controlfile_record_section;
select type,record_size,records_total,records_used
from v$controlfile_record_section
where type in('DATAFILE','TABLESPACE','REDO LOG');
使用v$parameter 来获取控制文件的名字,位置
select value
from v$parameter
where name='control_files';
每个控制文件所在磁盘,目录,文件名
col name for a45
select * from v$controlfile;
添加控制文件:
alter system set control_files=
'D:\Disk3\CONTROL01.CTL',
'D:\Disk6\CONTROL02.CTL',
'D:\Disk9\CONTROL03.CTL' scope=SPFILE;
控制文件备份:
alter database backup controlfile to 'D:\backup\control.bak';(要先建backup文件夹)
备份到追踪文件
alter database backup controlfile to trace;
复制控制文件
shutdown immediate
host copy: D:\Disk3\CONTROL01.CTL D:\Disk1\CONTROL01.CTL
host copy: D:\Disk6\CONTROL02.CTL D:\Disk1\CONTROL02.CTL
host copy D:\Disk9\CONTROL03.CTL D:\Disk3\CONTROL03.CTL
---------------------第五章 重做日志----------------
强制产生重做日志切换命令
alter system switch logfile
强制性产生检查点的命令:
alter system checkpoint
设置:FAST_START_MTTR_TARGET=900 秒来强制产生检查点
实例恢复的时间不会超过900秒
获取重做日志信息
select group#,sequence#,members,bytes,status,archived
from v$log;
获取重做日志组成员所在目录,状态
col member for a25
select * from v$logfile;
添加重做日志文件:
alter database add logfile
('D:\Disk3\redo4a.log','D:\Disk6\redo04b.log')
size 15M;
删除重做日志文件:
alter database drop logf
ile group 4;
添加联机重做日志成员
alter database add logfile member
'D:\Disk3\redo01b.log' to group 1,
'D:\Disk3\redo02b.log' to group 2,
'D:\Disk3\redo03b.log' to group 3;
删除重做日志成员:
alter system drop logfile member
'D:\Disk3\redo03b.log';
清除联机重做日志文件:(慎用)
alter database clear logfile group 组号;
如果崩溃的重做日志文件不能归档,unarchived 清除已经崩溃的重做日志文件避免归档
alter database clear unarchived logfile group 组号;
危险操作前备份:
col name for a55
select * from v$controlfile;
shutdown immediate
host copy D:\ORADATA\ORCL\CONTROL01.CTL D:\backup\
host copy D:\ORADATA\ORCL\CONTROL02.CTL D:\backup\
host copy D:\ORADATA\ORCL\CONTROL03.CTL D:\backup\
将口令文件和参数文件也复制到backup\
host copy D:\oracle_10g\database\*.* D:\backup\
----------------------------------------------------
OMF (Oraclee Managed Files)
自动管理和维护重做日志文件
alter system set DB_CREATE_ONLINE_LOG_DEST_1='D:\Disk3';
alter system set DB_CREATE_ONLINE_LOG_DEST_2='D:\Disk6';
alter system set DB_CREATE_ONLINE_LOG_DEST_3='D:\Disk9';
alter database add logfile;
获取重做日志信息
select group#,sequence#,members,bytes,status,archived
from v$log;
获取重做日志组成员所在目录,状态
col member for a25
select * from v$logfile;
alter database drop logfile group 4;
与手工不同自动从系统删除文件
----------------第六章 表空间和数据文件的管理----------
create tablespace jinlian----------->>>>>>>>>>>有问题
datafile 'D:\Disk2\moon\jinlian01.dbf' size 50 M,
'D:\Disk4\moon\jnnlian02.dbf' size 50 M
minimum extent 50K extent management dictionary
default storage (initial 50K next 50K maxextents 100 pctincrease 0);
验证:
select tablespace_name,block_size,extent_management,segment_space_management
from dba_tablespaces;
验证是否按要求配置:
select tablespace_name,initial_extent,next_extent,max_extents,min_extlen
from dba_tablespaces;
查看与配置有关的文件信息:
col file_name for a30
select file_id,file_name,tablespace_name
from dba_data_files
order by file_id;
创建本地管理的表空间
create tablespace jinlian_index
datafile 'D:\Disk6\moon\jinlian_index.dbf'
size 50 M
extent management local
uniform size 1M;
验证:like后的要大写??
select tablespace_name,block_size,extent_management,segment_space_management
from dba_tablespaces
where tablespace_name like 'JIN%';
create tablespace jinlian
datafile 'D:\Disk2\moon\jinlian.dbf'
size 50 M
创建还原表空间:
create undo tablespace jinlian_undo
datafile 'D:\Disk7\moon\jinlian_undo.dbf'
size 20 M;
select tablespace_name,status,contents
from dba_tablespaces
where tablespace_name like 'JIN%';
临时表空间:
col File for a25
col Tablespace for a15
select f.file#,t
.ts#, "File", "Tablespace"
from v$tempfile f,v$tablespace t;
where f.ts#=t.ts#;
创建临时表空间
create temporary tablespace jinlian_temp
tempfile 'D:\Disk8\moon\jinlian_temp.dbf'
size 10 M
extent management local
uniform size 2 M;
验证:like后的要大写??
select tablespace_name,block_size,extent_management,segment_space_management
from dba_tablespaces
where tablespace_name like 'JIN%';
创建默认临时表空间
col PROPERTY_NAME for a10
col PROPERTY_VALUE for a16
col DESCRIPTION for a20
select *
from DATABASE_PROPERTIES
where PROPERTY_NAME like 'DEFAULT%';
将inlian_temp临时表空间设置为默认表空间
alter database
default temporary tablespace jinlian_temp;
党不再处理金莲项目数据时候,改回原先默认的临时表空间
alter database
default temporary tablespace temp;
设置表空间为脱机状态
查询当前表空间状态
select tablespace_name ,status,contents
from dba_tablespaces
where tablespace_name like 'JIN%';
col name for a55
select file#,name,status
from v$datafile
where file#>=8;
设置为脱机状态
alter tablespace jinlian offline;
维护工作结束,改回联机
alter tablespace jinlian online;
只读表空间
alter tablespace jinlian read only;
改回来
alter tablespace jinlian read write;
改变表空间的存设置 >>>>>>>>>有问题:默认存储字句与分配策略不兼容
alter tablespace jinlian
default storage (initial 100 K next 100 k maxextents 200);
查看修改后的参数:
select tablespace_name,initial_extent,next_extent,max_extents,pct_increase,min_extlen
from dba_tablespaces
where tablespace_name like 'JIN%';
重置表空间的大小
查看那些表空间或数据文件可以自动扩展
col file_name for a40
set line 100
col tablespace_name for a15
select file_id,tablespace_name,file_name,autoextensible
from dba_data_files
where file_id>=2;
order by file_id;
将jinlian_index 表空间设置为自动扩展
alter database datafile
'D:\Disk6\moon\jinlian_index.dbf' autoextend on
next 1 M;
手工重置数据文件的大小,先查看大小
select file_id,file_name,tablespace_name,bytes/(1024*1024) MB
from dba_data_files
where tablespace_name like 'JIN%'
order by tablespace_name;
将某一个数据文件重新设置为100 M
alter datablase datafile 'D:\Disk2\Jinlian01.dbf' resize 100 M;
也可以向表空间添加新的数据文件
alter tablespace jinlian
add datafile 'D:\Disk6\moon\jinlian03.dbf'
size 20 M;
移动数据文件:
select file_id,file_name,tablespace_name
from dba_data_files
where file_name like '%ORADATA%'
order by file_id;
看状态
select tablespace_name ,status,contents
from dba_tablespaces
where tablespace_name not like '%JIN%';
该为脱机状态:
alter tablespace USERS offline;
alter tablespace INEX offline;
再利用操作系统命令复制到其他:
host copy: D:\er01.
dbf D:\Disk2\oradata\
重命名
alter tablespace users rename
datafile 'D:\oracle\ERS01.dbf'
to 'D:\er01.dbf'
再改为联机
alter tablespace users online
.....
验证:看状态
select tablespace_name ,status,contents
from dba_tablespaces
where tablespace_name not like '%JIN%';
移动系统表空间
shutdown immediate
startup mount
host copy D:\ORACLE\...\SYSTEM01.dbf D:\Disk1\oradata
alter database rename
file 'D:\ORACLE\...\SYSTEM01.dbf'
to 'D:\Disk1\oradata\SYSTEM01.dbf';
验证:
select file_id,file_name,tablespace_name
from dba_data_files
where file_name like '%ORACLE%'
ordr by file_id;
迁移数据字典和本地管理的表空间:
查看哪些是本来管理的:
select tablespace_name,block_size,extent_management,segment_space_management,min_extlen
from dba_tablespaces
where tablespace_name like 'JIN%';
execute DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL('JINLIAN');
验证:
重新迁移为数据字典管理的表空间:
execute DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_FROM_LOCAL('JINLIAN');
删除表空间:
drop tablespace 表空间名字 [including contents[and datafiles][cascate constraints]]
找到表空间和其对应的文件
select file_id,file_name,tablespace_name
from dba_data_files
where file_id>2
order by file_id;
删除表空间:
drop tablespace jinlian;
验证:
drop tablespac e jinlian_index including contents and datafiles;
查看临时表空间和其对应的文件:
col File for a25
col Tablespace for a15
select f.file#,t.ts#, "File", "Tablespace"
from v$tempfile f,v$tablespace t;
where f.ts#=t.ts#;
删除临时表空间:
drop tablespace jinlian_tem including contents and datafiles;
利用OMF 来管理表空间:之后表空间被创建时候,自动建立并存放在定义的文件下
alter system set
db_create_file_dest='D:\Disk6\oradata';
create tablespace guifei;
默认100M,再添加一个50M的。
select file_id,file_name,tablespace_name,bytes/(1024*1024) MB
from dba_data_files
where tablespace_name like 'GUI%';
alter tablespace guifei add datafile size 50 M;
-----------------------------第七章 存储结构和它们之间的关系-----------------------------
select tablespace_name,block_size,status,contents
from dba_tablespaces;
----------------------------第八章 管理还原数据---------------------------------
读一致性:
create table emp_tran
as select * from emp;
select empno,ename,job,sal
from emp_tran
where job='CLERK';
update emp_tran
set sal=2000
where job='CLERK';
查询数据库中还原数据的管理是自动的还是手动的
col name for a15
col value for a25
select name,value
from v$parameter
where name like '%undo%';
创建还原表空间:
create undo tablespace jinlian_undo
datafile 'D:\Disk7\moon\jinlian_undo.dbf'
size 20 M;
select ta
blespace_name,status,contents
from dba_tablespaces
where contents='UNDO';
为jinlian_undo 增加一个大小10M 的额外数据文件
alter tablespace jinlian_undo
add datafile 'D:\Disk8\moon\jinlian2_undo.dbf'
size 10 M;
验证:
col file_name for a20
col tablespace_name for a10
select file_id,file_name,tablespace_name,bytes/(1024*1024)
from dba_data_files
where tablespace_name like 'JIN%';
将jinlian_undo 设置为自动扩展:
select file_id,file_name,tablespace_name,autoextensible
from dba_data_files
where tablespace_name like 'JIN%';
alter database
datafile 'D:\Disk7\moon\jinlian_undo.dbf'
autoextend on;
还原表空间之间的切换:
alter system set UNDO_TABLESPACE=jinlian_undo;
改回来:
alter system set UNDO_TABLESPACE=UNDOTAS1;
删除还原表空间:
drop tablespace jinlian_undo;
验证:
select tablespace_name,status,contents
from dba_tablespaces
where contents='UNDO';
自动还原数据管理的一些参数
alter session set UNDO_SUPPRESS_ERRORS=true
还原数据在事物提交后至少保留900秒,动态参数
alter system set UNDO_RETENTION=1800;
验证
col name for a15
col value for a25
select name,value
from v$parameter
where name like '%undo%';
或得还原数据信息:
select to_char(begin_time,'hh:mm:ss') begin_time,
to_char(end_time,'hh:mm:ss') end_time,
undoblks,txncount,maxquerylen
from v$undostat;
-------------------第九章 创建数据库---------------------
口令文件:
orapwd file= 文件名 password=口令 entries=最大用户数
例如:
orapwd file=D:/..../orapwjinlian
password=wuda entries=3
之后初始化参数:
remote_login_passwordfile=exelusive
授权
grant sysdba to scott;
----------------第十章 管理表------------
获取数据行的ROWID
select empno,ename,job,sal,rowid
from emp
where sal>2000;
创建普通表:
create table scott.product
(
pcode number(8),
pname varchar2(30),
pdesc varchar2(100),
pprice number(6,2)
)
tablespace users;
创建数据字典管理的表:>>>>>>>>>>>>>>>>>>>有问题
create table scott.supplier
(
scode number(8),
aname varcher2(25),
contact varchar2(15),
phone varchar2(15),
fax varchar2(15)
)
storage(initial l00K next 100K
pctincrease 0
minextents 1
maxextents 8
)
tablespace jinlian;
验证:
select table_name,tablespace_name,initial_extent
from dba_tables
where owner='SCOTT';
创建临时表:
create global temporary table
scott.emp_temp
on commit preserve rows
as select *
from scott.emp
where job not like 'SAL%';
on commit preserve rows:说明数据行在整个会话可见
on commit delete rows :说明数据行只有在事务中可见
select empno,ename,job,sal,deptno
from emp_temp;
临时表不使用表空间使用临时段
col table_name for a15
col tablespa
ce_name for a15
select table_name,tablespace_name,temporary
from dba_tables
where owner='SCOTT';
表的维护和管理:
alter table scott.product
pctfree 20
pctused 50;
从dba_segments获取操作表的product的相关信息
select segment_name,tablespace_name,extents
form dba_segments
where owner='SCOTT'
and SEGMENT_NAME like 'PRO%';
为scott 的表product增加一个extents的磁盘空间:
alter table scott.product
allocate extent;
非分区表的重组:
scott用户的数据存放在那些表空间中:
col tablespace_name for a15
col segment_name for a20
select segment_name,tablespace_name,extents,blocks
from dba_segments
where owner='SCOTT';
哪些是表,哪些是索引
col object_name for a15
select object_id,object_name,object_type,status,created
from dba_objects
where owner='SCOTT';
pk_dept 和pk_emp基于哪些表
select index_name,table_name,tablespace_name,status
from dba_indexes
where owner='SCOTT';
把scott 用户下的所有段从系统表空间移到user表空间
alter tables scott.emp
move tablespace users;
验证:from dba_segments
from dba_objects
from dba_indexes
alter index scott.pk_emp rebuild
tablespace indx;
验证:from dba_indexes
列的修改:
alter table user_name.table_name
rename column old_column_name
to new_colum_name
alter table user_name.table_name
drop column culumn_name
casade constraints checkpoint row_number;
删除某一列:
alter table 用户名.表名
set unused 列名
cascade constraints;
当数据空闲时候删除
alter table 用户名.表名
drop unused columns checkpoint 行数;
如果系统中途崩溃
alter table 用户名.表名 drop columns continue 行数
当一个数据库已经不再需要,可以使用
truncate table 全部删除或截断
truncate table 用户名.表名
删除数据,保留结构,释放空间,不触发
drop table 用户名.表名[cascade constraints];
------------------第十一章 索引的管理和维护------------------
查看scott用户的索引基于的表,所在的表空间,索引的分类和索引的状态信息
col index_type for a12
col tablespace_name for a15
select index_name,table_name,tablespace_name,index_type,uniqueness,status
from dba_indexes
where owner='SCOTT';
scott 用户的索引基于的表和列信息
col index_name for a12
col table_name for a12
col column_name for a15
col index_owner for a12
col table_owner for a12
select index_name,table_name,column_name,index_owner,table_owner
from dba_ind_columns
where table_owner='SCOTT';
创建索引:
create index scott.emp_ename_idx
on scott.emp(ename)
pctfree 20
storage(initial 100k next 100k
pctincrease 0 maxextents 100)
tablespace jinlian;
create bitmap index scott.emp_job_idx
on scott.emp(job)
pctfree 20
storage(initial 100k next 100k
pctincrease 0 maxextents 100)
tablespace jinlian
;
查看参数是否按照命令设置的:
select index_name,pct_free,pct_increase,initial_extent,next_extent
from dba_indexes
where owner='SCOTT';
本地管理的表空间无法改变next_extent 的大小
alter index scott.emp_ename_idx rebuild
pctfree 40
storage(next 300k);
在大规模装入数据前,为了避免索引段的自动扩展,手工分配磁盘空间
查看当前索引短的饿磁盘空间分配情况
col segment_name for a15
select segment_name,segment_type,tablespace_name,extents
from dba_segments
where owner='SCOTT'
and segment_type='INDEX';
手工的为scott.emp_ename_idx增加一个extent的磁盘空间
alter index scott.emp_ename_idx
allocate extent;
回收磁盘空间
alter index scott.emp_ename_idx coalesce;
标识索引的使用情况
conn scott
开启监督索引使用的DDL语句
alter index emp_ename_idx monitoring usage;
发出一个查询
select ename,job,sal
from scott.emp
where ename like 'C%';
现在使用v$object_usage 来获取索引emp_ename_idx 的使用情况
col index_name for a15
col table_name for a12
select * from v$object_usage;
关闭索引监督
alter index emp_ename_idx nomonitoring usage;
删除索引:
dorp index scott.emp_ename_idx;
drop index scott.emp_job.idx;
----------------------第十二章 管理和维护数据完整性-----------------------------
Disable novalidate 禁止而无效 不做约束检查 数据可能不遵守约束定义
Disable validate 禁止而有效 表中约束数据不能任何修改 约束索引删除 约束被禁止
Enable novalidate 激活而无效 表可能含违反,但新违反不能输入
Enable validate 激活而有效 任何违反约束不能存在
完整性约束分为两类:延迟性和非延迟性
完整性约束的检查与定义:
从数据字典dba_constraints 获取scott用户拥有的约束信息
col constraint_name for a15
col table_name for a12
select constraint_name,table_name,constraint_type,status,deferrable,deferred,validated
from dba_constraints
where owner='SCOTT';
修改某些约束的设置:
set constraint scott.pk_depino,scott.pk_emp immediate;
将报错
set constraint scott.fk_deptno,scott.pk_emp deferred;
同样报错:不能修改非延迟性约束的延迟状态
建立一个延迟约束
alter table scott.event
add constraint event_evtid_pk
primary key(evtid)
deferrable
using index
storage(initial 300k next 300k)
tablespace jinlian;
验证:
select segment_name,segment_type,tablespace_name,initial_event,next_extent
from dba_segments
where tablespace_name like '';
col constraint_name for a15
col table_name for a12
select constraint_name,table_name,constraint_type,status,deferrable,validated
from dba_constraints
where owner='SCOTT';
set constraint scott.pk_depino,scott.pk_emp immediate;
set constraint scott.fk_deptno,scott.pk_emp deferred;
可以用了是因为定义了延迟约束
也是
说可以修改定义了延迟性约束的延迟状态
不可以修改定义了非延迟约束的延迟状态
关闭开启约束
alter table scott.person
disable novalidate constraint person_personid_pk;
验证:
from dba_constraints
开启personid 列上上的主键约束
alter table scott.person
enable novalidate constraint person_personid_pk;
desc exceptions;
重新命名
alter table scott.emp
rename constraint pk_emp
to emp_empno_pk;
alter table scott.person
drop constraint event_evtid_pk;
处在enable novalidate 状态约束并不检查表中的数据。而是检验输入的数据,此时并不在表上加锁
,但是对约束也有一些限制。那就是主键和唯一键必须使用非惟一索引。
select index_name,uniqueness
from dba_indexes
where owner='SCOTT';
找到违反约束的数据行:
运行utlexpt1.sql脚本
D:\oracle_10g\RDBMS\ADMIN\utlexpt1.sql
执行 exceptions 选项的alter table 语句
在exceptions 表上使用子查询来锁定无效的数据
改正错误
重新执行带有开启约束字句的alter table 语句
SQL>@D:\oracle_10g\RDBMS\ADMIN\utlexpt1.sql
desc exceptions
alter table scott.person
enable validate constraint person_personid_pk
exceptions into system.exceptions;
select rowid,personid,name,intro
from scott.person
where rowid in(select row_id from exceptions)
fro update;
然后利用一般update 修改
alter table scott.person
enable validate constraint person_personid_pk;
----------------------------第十三章--------------------------------------
create user 用户名
indentified {
by
口令|externaliy|globally as external name
[deffault tablespace 表空间名]
[temporary tablespace 表空间名]
[quota {正整数 [K|M] | unlimited} on 表空间名
[quoto {正整数 [K|M] | unlimited} on 表空间名]...]
[password expire]
[account{lock|unlock}]
[profile{概要文件名|default}]
create user dog
identified by wangwang
default tablespace jinlian
temporary tablespace jinlian_temp
quota 68M on jinlian ------->该用户使用jinlian最多68M
quota 28M on users ------->该用户使用user表空间最多为28M
password expire; ----->每次登录,密码过期,重新设置
col username for a10
col default_tablespace for a18
col temporary_tablespace for a18
set line 120
select username,defualt_tablespace,temporary_tablespace,created
from dba_users
where default_tablespace like 'JIN%';
看看dog表空间的配额
select username,tablespace_name,bytes/1024/1024 MB,max_bytes/(1024*1024) "Max MB"
from dba_ts_quotas
where username='DOG';
改变用户在表空间上的配额:
alter user dog
quota 0 on users;
alter user dog
quota 38M on jinlian;
通过查配额验证一下
删除用户:
drop user dog;
创建概要文件:
create profile pioneer_prof limit
failed_login_attempts 4 登陆系统最多可以试4次
password_lock_time unlimited 4次后永远
被锁住
pwssword_life_time 91 口令有效期91天,之后修改
password_reuse_time 28 一个口令失效后28天后才能使用,防止使用原来的旧口令
password_grace_time 7 当一个口令失效后给7天宽限期,如果没有这段时间没有改变,无法登录
sessions_per_user 3 可以有3个连接数
cpu_per_session 16800 没有会话处理器时间不超过168秒
logical_reads_per_session 23688 每个会话最多的逻辑阅读量为23688个数据块
connect_time 180 每个用户的连接时间最多为180min
idle_time 28; 每个用户的空闲时间为28min,之后踢出系统并回滚
select * from dba_profiles
where profile like 'PION%';
-------------------------------十四章 管理权限---------------------------------
create user
alter user
select any table
update any table
delete any table
create any table
drop any table
alter any table
alter any table
create table
create tablespace
drop tablespace
alter tablespace
unlimited tablespace
create any index
drop any index
alter any index
create session
alter session
create view
create sequence
create procedure
----sysoper 和sysdba 系统权限
startup
shutdown
alter database open |mount |backup
archivelog
recover
create spfile
sysdba系统权限所包括的授权
sysoper 权限with admin option
create database
alter tablespace ace begin/end backup
recover database until
----------------------------------------
create user dog identified by wangwang;
create user cat identified by miaomiao;
create user pig identified by hengheng;
create user fox identified by loveyou;
grant create session,select any table,create table,create view to cat;
revoke create session,select any table,create table,create view from cat;
grant create session,select any table,create table,create view
to cat with admin option;
conn cat/miaomiao
grant create session,select any table,create table,create view
to dog with admin option;
conn dog/wangwang
grant create session,select any talbe,create table,create view to pig;
查看用户权限可以将哪些权限下放
select *from dba_sys_privs where grantee in('CAT','DOG','FOX','PIG');
revoke create view from cat;
select * from dba_sys_privs
where grantee='CAT';
select * from dba_sys_privs
where grantee in('DOG','FOX','PIG');
查看自己有哪些权
conn fox/loveyou
select * from session_privs;
对象权限
execute
alter
select
insert
update
delete
index
references
grant 对象权限|all(列名[列名...])]
on 对象名
to [用户名|角色名|public]
[width grant option]
将某个软件包的执行权限赋给system
grant execute on dbms_space_admin to system;
grant select on emp to public ;
grant update(sal) on emp to cat;
grant update(job)
on emp
to cat
with grant option;
检查是否成功?
select * from user_tab_privs_made;
查看列上的对象权限
s
elect * from user_col_privs_made;
conn cat/miaomiao
grant update(job) on scott.emp
to pig,dog
with grant option;
-------------第十五章 管理角色------------------
create role clerk
identified by money;
如果使用了not identified (默认) 和
indentified externally 该角色自动授予width admin option选项。
create role sales
identified by money;
create role manager
identified externally;
验证:
select * from dba_roles
where role in ('CLERK','SALES','MANAGER');
角色修改
alter role clerk
identified externally;
alter role sales
not identified;
角色的授权
grant create session,create table,create view to clerk;
grant select any table ,clerk to manager;
select * from role_sys_privs
where role in ('CLERK','SALES','MANAGER');
也可以利用数据字典dba_role_privs
select * from dba_role_privs
where granted_role like 'CL%';
grant manager to cat with admin option;
col username for a10
select * from user_role_privs;
查看所有权限
select * from session_privs;
创建默认角色
conn system/tujiazu
grant sales to cat;
alter user cat default role none;
默认角色在下列情况下不能使用
通过其他角色授予的角色
没有直接授予该用户的角色
通过外部服务如操作系统管理的角色
alter user cat default role clerk,manager;
alter user cat default role all;
alter user cat default role all except sales;
激活和禁止角色,角色权限被收回
set role none;
激活manager必须使用先前创建的密码
set role manager identified by 密码
激活除了manager的所有角色
角色的回收和删除:
为了方便,去掉密码
alter role clerk not identified;
alter role manager not identified;
select * from dba_roles
where role in('CLERK','SALES','MANAGER');
grant clerk,manager,sales
to cat,dog,pig,fox;
select * from dba_roles where role in('CLERK','SALS','MANAGER');
set role all except manager;
查看授权是否成功:
select * from dba_role_privs
where grantee in('CAT','DOG','PIG','FOX');
revoke manager ,sales
from pig,fox;
将角色授予所有的用户
grant manager,sales to PUBLIC;
revoke manager ,sales
from public;