oracle笔记——第五天:约束,权限
来源:互联网 发布:聚合数据使用必须认证 编辑:程序博客网 时间:2024/05/19 17:25
维护数据的完整性(约束、触发器、应用程序、过程、函数)
--约束(unique、not null、primary key、foregin key、check)
商店售货表设计
--商品表
create table goods(
goodsId char(8) primary key,--主键
goodName varchar2(30),--商品名字
unitprice number(10,2) check (unitprice >0),--商品单价
category varchar2(8),--商品类别
provider varchar2(30)--商品供应商
);
--顾客表
create table customer(
customerId char(8) primary key,--主键
name varchar2(50) not null,
address varchar2(50),
email varchar2(50) unique, --唯一
sex char(2) default '男' check(sex in ('男','女')),
cardId char(18)
);
--购买表
create table purchase(
customerId char(8) references customer(customerId),
goodsId char(8) references goods(goodsId),
nums number(5) check(nums between 1 and 30)
);
---------------------------------
1.商品不能为空
alter table goods modify goodsName not null;
2.增加姓名约束不能为空
alter table customer add constraint cardunique unique(cardId);
3.增加客户住址只能是 ‘海淀’,‘曹阳’,‘东城’,‘西城’,
alter table customer add constraint addresscheck check (addresscheck in ('海淀','朝阳','东城','西城'));
--删除约束
alter table 表明 drop constraint 约束名称
--显示约束信息
select constraint_name,validated,constraint_type,status from user_constraints where table_name='goods';
1.表级定义:定义列的同时定义约束
2.列级定义:定义完所有列后,在定义约束
--------------------------------------
-------管理索引
--为什么添加索引之后,查询的速度会更快
------创建索引
1.单列索引
create index nameIndex on customer(name);--某张表,某列
2.符合索引
create index emp_idx1 on emp(job,ename);
create index emp_idx1 on emp(ename,job);
--使用原则
1.在大表上建立索引才有意义
2.在where 子句货连接条件上经常使用的列上建立索引
3.索引的层次不要超过四层
--索引的缺点
1.建立索引,系统要占用大约表1.2倍的硬盘和内存空间来保持索引
2.更新数据时,系统要额外的时间来更新索引。
--显示表的索引
select index_name,index_type from ump(sal) to monkey
2.授予alter
grant alter on emp to blake;
3.授予execute
4.授予index权限
5.使用with grant option(对象权限)with admin option(系统权限)
---------------角色----------------------------------------
--预定义角色
1.connect
alter session
create cluster
create database link
create session
create table
create view
create sequence
2.resource
create cluster
create indextype
create table
create sequence
create type
create procedure
create trigger
3.dba
具有所有的系统权限,及with admin option,
默认的dba用户为sys,system,他们可以将任何的权限授予其他用户
但是要注意的是dba角色不具有sysdba和sysoper的特权(启动和关闭数据库)
--自定义角色
1.create role 角色名 not identified;(不验证)
2.create role 角色名 identified by shunping(数据库验证)
--给自定义角色授予权限
3.grant insert,update,delete on scott.emp to 角色名
--分配角色给用户
4.grant 角色名 to blake with admin option(由dba实现)
--删除角色drop 角色名
--显示角色的信息
select *from dba_roles;
--显示角色具有的系统权限
select privilege,admin_option from role_sys_privs where role='CONNECT'
--显示角色具有的对象权限
select granted_role,default_role from dba_role_privs where grantee='SYSTEM'
--约束(unique、not null、primary key、foregin key、check)
商店售货表设计
--商品表
create table goods(
goodsId char(8) primary key,--主键
goodName varchar2(30),--商品名字
unitprice number(10,2) check (unitprice >0),--商品单价
category varchar2(8),--商品类别
provider varchar2(30)--商品供应商
);
--顾客表
create table customer(
customerId char(8) primary key,--主键
name varchar2(50) not null,
address varchar2(50),
email varchar2(50) unique, --唯一
sex char(2) default '男' check(sex in ('男','女')),
cardId char(18)
);
--购买表
create table purchase(
customerId char(8) references customer(customerId),
goodsId char(8) references goods(goodsId),
nums number(5) check(nums between 1 and 30)
);
---------------------------------
1.商品不能为空
alter table goods modify goodsName not null;
2.增加姓名约束不能为空
alter table customer add constraint cardunique unique(cardId);
3.增加客户住址只能是 ‘海淀’,‘曹阳’,‘东城’,‘西城’,
alter table customer add constraint addresscheck check (addresscheck in ('海淀','朝阳','东城','西城'));
--删除约束
alter table 表明 drop constraint 约束名称
--显示约束信息
select constraint_name,validated,constraint_type,status from user_constraints where table_name='goods';
1.表级定义:定义列的同时定义约束
2.列级定义:定义完所有列后,在定义约束
--------------------------------------
-------管理索引
--为什么添加索引之后,查询的速度会更快
------创建索引
1.单列索引
create index nameIndex on customer(name);--某张表,某列
2.符合索引
create index emp_idx1 on emp(job,ename);
create index emp_idx1 on emp(ename,job);
--使用原则
1.在大表上建立索引才有意义
2.在where 子句货连接条件上经常使用的列上建立索引
3.索引的层次不要超过四层
--索引的缺点
1.建立索引,系统要占用大约表1.2倍的硬盘和内存空间来保持索引
2.更新数据时,系统要额外的时间来更新索引。
--显示表的索引
select index_name,index_type from ump(sal) to monkey
2.授予alter
grant alter on emp to blake;
3.授予execute
4.授予index权限
5.使用with grant option(对象权限)with admin option(系统权限)
---------------角色----------------------------------------
--预定义角色
1.connect
alter session
create cluster
create database link
create session
create table
create view
create sequence
2.resource
create cluster
create indextype
create table
create sequence
create type
create procedure
create trigger
3.dba
具有所有的系统权限,及with admin option,
默认的dba用户为sys,system,他们可以将任何的权限授予其他用户
但是要注意的是dba角色不具有sysdba和sysoper的特权(启动和关闭数据库)
--自定义角色
1.create role 角色名 not identified;(不验证)
2.create role 角色名 identified by shunping(数据库验证)
--给自定义角色授予权限
3.grant insert,update,delete on scott.emp to 角色名
--分配角色给用户
4.grant 角色名 to blake with admin option(由dba实现)
--删除角色drop 角色名
--显示角色的信息
select *from dba_roles;
--显示角色具有的系统权限
select privilege,admin_option from role_sys_privs where role='CONNECT'
--显示角色具有的对象权限
select granted_role,default_role from dba_role_privs where grantee='SYSTEM'
0 0
- oracle笔记——第五天:约束,权限
- 笔记:ORACLE数据库基础学习 第五天
- oracle基础教程(第五天)管理索引、权限和角色
- OpenStack学习笔记————第五天
- 《30天自制操作系统》学习笔记——第五天
- Unity3D笔记第五天——Animation动画
- oracle第五天
- Oracle 学习第五天
- oracle培训第五天
- java第五天--protected权限
- 第五天:听课笔记
- 第五天的笔记
- 第五天学习笔记
- 第五天学习笔记
- dom第五天笔记
- java 第五天笔记
- 学习笔记第五天
- 第五天——PRESENT
- oracle笔记——第四天:数据库管理
- think in java interview-高级开发人员面试宝典(九)
- jsp中获取系统时间,并转换成指定格式
- 使用Editplus编译C语言
- 安卓 jni C/C++ logcat 调试输出
- oracle笔记——第五天:约束,权限
- 测试基本知识总结
- 查询数据库字符集(oracle服务器端字符集)命令
- 网页细节设置和推广才是决定SEO成败的关键
- mysql 我常用的命令 数据库备份还原等
- STL泛型编程和设计新思维
- think in java interview-高级开发人员面试宝典(十)
- linux安装libpcap
- 随机正负整数