Oracle day4

来源:互联网 发布:旋转木马js效果带左右 编辑:程序博客网 时间:2024/04/28 03:31

数据库=====》 数据建模需注意的事项


软件开发流程:
1、跟客户确定系统需求
2、形成需求分析文档
3、做设计文档(相关数据===实体、表、数据、抽象~)
4、编码
5、测试、试运行
6、产品上线、运行


如何把模型想法转变为实体====把实体如何转换为表关系

Entity       实体         表和类之间
Attribute     属性         属性和表中的字段的关系
Relationship    关系         关系的映射    表和表之间



建表的三大范式:
第一范式:数据表当中每一列都是不可再分割的,每个表当中只能包含一个实例信息;
   
第二范式:要求数据表中的每个实例或者行可以被唯一的区分,为实现区分通常需要给每列添加唯一标识列(主键)做为唯一的标识;

第三范式:要求一数据库表中不包含已经在其他表中已包含的非主键字信息属性不依赖于其他的非主属性。


约束:
PK        primary key    唯一且非空(主键约束)
FK        foreign key     一张表要引用另一张表(外键约束)
UK        unique key    唯一可为空(唯一约束)
NOT NULL    设置不可为空(非空约束)


类型:
varchar2(32)    可变长的    "abcddd"
varchar(32)
number
number(p,s)      有小数位数
date         日期
long        大文本    2GB
clob        存入二进制数据类型    图像、声音


建表语法
CREATE TABLE 表名(
字段    类型,
字段    类型,
.......
字段    类型
);


PK        primary key   
create table Test(
id number primary key,
name varchar2(32) not null
);




FK        foreign key 
create table Test1(
test1_id number primary key,
test1_name varchar2(32) not null,
);

create table Test2(
test2_id number references test1(test1_id),
test2_name varchar2(32) not null,
primary key(test2_id)
);

关键字:FK=======》references

UK        unique key   
create table Test(
id number unique,
name varchar2(32) not null
);


NOT NULL
create table Test(
id number,
name varchar2(32) not null
);



添加记录
insert into 表名 values(值);
insert into test values(1,'123');


一对一:
card身份证号    person人
create table  person(
id     number    primary key,
name     varchar2(32)
);

create table card(
c_id     number    references person(id),
name    varchar2(32),
primary key(c_id)
);



一对多:
人person      书book
create table person(
id    number    primary key,
name     varchar2(32)    not null
);

create table book(
book_id     number    primary key,
name    varchar(32)    not null,
person_id number references person(id)
);



多对多:
学生student     课程course
create table student(
s_id number primary key,
s_name varchar2(32)    not null
);

create table course(
c_id number primary key,
c_name varchar2(32)    not null
);


//中间表
create table   StudentSelectCourse(
s_id number references   student(s_id),
c_id number references   course(c_id),
primary key(s_id,c_id)
);
 

原创粉丝点击