Oracle day4

數據庫=====》 數據建模需注意的事項


軟件開發流程:
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)
);
 

發佈了45 篇原創文章 · 獲贊 4 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章