数据库结构:
Oracle服务器组成:实例,数据库
实例:内存(SGA,PGA),后台进程(DBWR,LGWR,SMON,PMON,CKPT)(数据读写,日志读写,系统监视,进程监视,检查点)数据库:(数据文件,日志文件,控制文件) 辅助(口令,参数,归档日志)
一、表空间的管理(数据空间的管理)
1)创建表空间
create tablespace erp_tbs
datafile 'D:\APP\ORACLE\ORADATA\ORCL\erp01.dbf'
size 10 M
autoextend on
maxsize 100 M;
2)修改表空间--添加文件
alter tablespace erp_tbs
add DataFile 'D:\APP\ORACLE\ORADATA\ORCL\erp02.dbf' SIZE 10 M;
3)修改表空间--删除文件
alter tablespace erp_tbs
drop DataFile 'D:\APP\ORACLE\ORADATA\ORCL\erp02.dbf';
4)删除表空间
drop tablespace erp_tbs ;
drop tablespace erp_tbs including contents;
drop tablespace erp_tbs including contents and datafiles;
二、用户和授权
create user student1 identified by pass123;
alter user student1 default tablespace testDemo;
drop user student1;
drop user student1 cascade;
alter user scott account unlock;
--授予系统权限
grant create session to student1;
grant create table to student1;
--收回权限
revoke create session from student1;
revoke create table from student1;
--授予角色权限
grant connect,resource to student1;
--收回角色权限
revoke connect,resource from student1;
--角色管理
create role banZhang;--班长
grant connect,resource to banZhang;
drop role banZhang;
--对象权限管理
grant select on scott.emp to student1;
grant all on scott.emp to student1;
revoke all on scott.emp from student1;
三、模式对象
1.表对象
数据类型 char,varchar2,number,date,timestamp,clob,blob
create table employee
(
id number(5) not null,--序号
name varchar2(20) not null,--名称
birthday date not null,--生日
sex char(1) not null --性别
);
drop table employee;
select * from employee;
约束【非空,主键,检查,唯一键,默认,外键】
【alter table employee modify sex char(1) not null;】
alter table employee add constraints pk_emp_id primary key(id);
alter table employee add constraints ck_emp_sex check(sex in('F','M','N'));
alter table employee add constraints uq_emp_name unique(name);
【alter table employee modify birthday date default(sysdate);】
主键和唯一的区别:
主键只有一个,唯一可以有多个
主键不能为空,唯一可以为空
关系表
create table salary
(
employeeid number(5) not null,
money number(18,2) not null
);
alter table salary add constraints fk_sal_emp_id foreign key(employeeid) references employee(id);
四、表的设计(数据库范式) 要满足23范式
1.字段尽量不可分。
2.有主键,非主键字段依赖主键。
3.非主键字段不能相互依赖。(跟主键有直接关系)