一、管理员身份登陆:sqlplus/nolog--->conn/as sysdbasql
二、普通用户登陆:sqlplus/nolog---->conn 用户名/密码数据库
三、管理员切换到普通用户:conn 用户名/密码session
四、普通用户切换到管理人员:conn sys as sysdba,而后输入密码回车oracle
Connect角色---》普通用户ide |
CONNECT SESSION-修改会话函数 Create cluster--创建簇族ui Create database link--创建数据库链接spa Create sequence--创建序列操作系统 Create session--创建会话日志 Create synonym--创建同义词 Create view--创建视图 |
Resource角色--》开发人员 |
Create cluster--创建簇族 Create procedure--创建过程 Create sequence--创建序列 Create table--建表 Create trigger--创建触发器 Create type--创建类型 |
Dba角色--》管理员【具有全部系统权限,可是没法启动和关闭数据库】 |
备份任何表、执行任何操做、查询任何表 |
建立角色:create role角色名 not identified(创建公用角色)/create role 角色名 identified by密码(创建私用角色)
三、角色受权:
3.1建立用户没有分配任何权限的时候,oracle自带的上sqlplus上登陆该用户会报错
3.2 grant 权限名称 to 角色名【注意:系统权限unlimited tablespace 和对象权限with grant option选项不能赋予给角色 】
四、显示角色信息
4.1查询角色信息:select * from role_sys_privs where role = '角色名称'
4.2 查询全部的角色:select * from dba_roles
4.3查询角色系统权限:select privilege,admin_option from role_sys_privs whererole='角色名'
4.4查询角色对象具备的权限:select privilege,admin_option from dba_tab_privs where role='角色名'
4.5查询用户具备角色以及默认角色:select grant_role from dba_sys_privs where grantee='用户名'
4.6将角色分配给用户:grant 角色名 to 用户名 with admin option[加上with admin option是为了用户能够将system分配给它的角色分配给别的其余用户]
4.7删除角色:drop role角色名称
(1)查看oracle系统权限:select * from sys_privilege_map
(2)分配权限:grant 权限名称1,权限名称2 to 用户名 with admin option
(3)回收系统权限:revoke create session from 用户名
前提:Smith用户访问scott.emp表
(1)经常使用的对象权限:alter、delete、select、insert、update、index、reference引用、execute
(2)查看对象权限:select distinct privilege from scott.emp
(3)授予对象权限:grant select on emp to monkey --受权查询权限给monkey/grant delete on emp to monkey--受权删除权限给monkey【也能够一次性授予权限:grant all on em to monkey】
(4)授予更具体的权限(好比对列的操做):grant update on emp(sal) to monkey---受权monkey用户emp表sal列的修改权限
(5)授予execute权限[用户要执行其余的方案的包、过程、函数必需要有execute权限]
(6)授予index权限[用户在表scott.emp表上创建索引,须要index权限]
(7)使用with grant option选项【该选项用于转授对象权限,只能授予用户,不能授予角色】
4.1建立用户:create user 用户名 identifiled by 密码
4.2删除用户:drop user 用户名
4.3查看全部用户:select * from dba_users/all_users或者select * from user_users
4.4查看用户角色
(1)当前用户被激活的角色:select * from session_roles
(2)当前用户被授予的角色:select * from user_role_privs
(3)所有用户被授予的角色:select * from dba_role_privs
(4)查看某个用户拥有的角色:select * from dba_role_privs where grantee='用户名'
表空间--》用户--》表
一、建表空间:create tablespace 表间名 datafile '数据文件名【路径能够沿用系统自带数据文件,可是记得修改文件名】' size 表空间大小
Oracle数据库:数据库的物理结构是由数据库的操做系统文件所决定,每个Oracle数据库是由三种类型的文件组成:数据文件
[select * from v$logfile]、日志文件和控制文件[查看控制文件存放地址:select name from v$controlfile]。数据库的文件为数据库信息提供真正的物理存储(就是数据文件)
oracle物理数据文件【查看数据文件:select name v$datafile】
一个oracle数据库有一个或多个数据文件
一个数据文件只与一个数据库链接
一旦创建,数据文件只增不减
一个表空间由一个或多个数据文件组成
建用户:create user 用户名 identified by 密码 default tablespace 表空间
给用户受权:grant connect ,resource to 用户名[grant dba to 用户名]
建表:create table 表名
(1)、案例:
create tablespace data_test datafile 'D:\APP\YITOP\ORADATA\ORCL\TEST.DBF' size 2000M;
Tablespace created【建表空间和数据文件】
create user wangt identified by wtwrws666 default tablespace data_test;【建用户】
grant connect,resource to wangt;和grant dba to wangt;
conn wangt/wtwrws666[从管理员切换到普通用户]
建表:语法格式alter table 表名 add constraint 约束名 约束内容【alter table info add constraint ck_info_age check(age>=0and age<=100)】
修改表
重命名表:rename 表名 to 新表名
向表中添加注释:comment on table 表名 is ‘注释文字’
更新表数据:update 表名 set 列名=’新值’ where 条件
修改列
修改列名:alter table 表名 rename column 列名 to 新列名
向列中添加注释:comment on column 表名.列名 is ‘注释文字’
修改列的属性:alter table 表名 modify 列名 varchar2(字符长度)/number(精度)/char(数据类型/default ‘默认值’);
插入数据到表中:insert into 表名 values(‘数据’,’’,’’,’’)
3.1删除表字段
alter table 表名 drop column 字段名
语法:select[distinct] * |列名称 [别名],列名称 [列名], from表名称[别名][where 过滤条件(s)][order by 字段[ASC|DESC],……]
(1)alter table 表名 add constraint 约束名(约束名简写_表名)约束(字段名)
例如:添加约束键:alter table INFOS add constraint ck_infos_check check(age>=0 and age<=100)
添加外键:alter table scores add constraint fk_scores_infos_stuid foregin key(stuid) references infos(stuid) references infos(stuid)
主键约束:alter table 表名 add constraint 约束名称 primary key(列名)
外键约束: alter table 表名1 add constraint 约束名称 foreign key(列名) references 表名2(列名)
检查约束:alter table 表名 add constraint 约束名称 check(检查条件)
不为空:alter table 表名 add constraint 约束名称 not null(列名)
惟一约束:alter table 表名 add constraint 约束名称 unique(列名)
默认值约束:alter table 表名 add constraint 约束名称 default ‘默认值’
给列添加约束
alter table 表名 add 字段名+字段约束