資料庫設計三正規化

2021-07-27 21:54:24 字數 2776 閱讀 5209

第一正規化

1. 資料庫中的所有欄位都具有單一屬性

2.單一屬性的列是由基本資料型別所構成的

3.設計出來的表是簡單的二維表

第二正規化 : 在滿足第一正規化的基礎之上滿足以下條件

要求一張表中值具有乙個業務主鍵,也就是說符合第二正規化的表中不能存在非主鍵列只對部分主鍵的依賴關係。

非主鍵列只對部分主鍵有依賴關係,這種情況只出現在復合主鍵的表中,也說是所這種表由2列或2列以上的資料組成主鍵。

因此,如果我們表中的主鍵只包含一列資料,那麼這張表一定是符合第二正規化要求的。

舉例說明,如下為學生選課資訊表

create table selectcourse (

student_number int not null comment '學號'  ,

student_name varchar(16) not null comment  '姓名' ,

student_*** char(1) not null comment 『性別』  ,

school_name varchar(16) not null comment '學生所在學院'

school_phone char(16) not null comment '學院****'

course_name varchar(16) not null comment ' 課程'  ,

score int not null comment comment '成績'  ,

point int not null comment comment '學分'  ,

primary_key(student_number, course_name) );

在selectcourse表中,由student_number和course_name組成復合主建, 但是point學分列只和course_name課程列相關,與student_number學號列無任何關係。也就是說這張表存在非主鍵列point只對部分主鍵course_name的依賴關係,因此這張表的設計不符合第二正規化的要求。

為了符合第二正規化的要求,我們把上述的selectcourse表拆分成3張表,以符合第二正規化要求。

create table student(

student_number int not null comment '學號'  ,

student_name varchar(16) not null comment '姓名' ,

student_*** char(1) not null comment 『性別』,

school_name varchar(16) not null comment '學生所在學院'

school_phone char(16) not null comment '學院****'

primary_key(student_number));

create table course_info(

course_name varchar(16) not null comment ' 課程'  ,

point int not null comment comment '學分'  ,

primary_key( course_name) );

create table student_course_info(

student_number int not null comment '學號'  ,

course_name varchar(16) not null comment ' 課程'  ,

score int not null comment comment '成績'  ,

primary_key(student_number,course_name));      

拆分之後,學生資訊表student和課程資訊表course_info由單一元件構成,肯定符合第二正規化要求,而且學生課程資訊表student_course_info中,成績列score必須同時依賴於student_number和course_name,也不存在部分依賴關係,所以也符合第二正規化要求。

第三正規化 :

每個非主屬性即不部分依賴於也不傳遞依賴於業務主鍵。也就是在第二正規化的基礎之上消除非主屬性對主鍵的傳遞依賴。

在上述的例子中,student表中,學生所在的學院school_name與學生的學號student_number有直接的對應關係,但是學院****school_phone與學生的學號student_number無直接的依賴關係,學院****school_phone依賴於學生所在的學院school_name,進而間接的依賴與學生的學號student_number。因此student表存在非主鍵對主鍵的傳遞依賴關係,所以不符合第三正規化。

為了符合第三正規化的需求,將student表拆分成2張表。

create table student_info(

student_number int not null comment '學號'  ,

student_name varchar(16) not null comment '姓名' ,

student_*** char(1) not null comment 『性別』,

school_name varchar(16) not null comment '學生所在學院'

primary_key(student_number));

create table school_info(

school_name varchar(16) not null comment '學院名詞'

school_phone char(16) not null comment '學院****'

primary_key(school_name));

資料庫正規化 三正規化設計

資料庫第一正規化 原子性 表中每一列都不可以再分割成更小的列 資料庫第二正規化 不產生區域性依賴 每張表只描述一件事情 資料庫第三正規化 表中每列都直接依賴於主鍵,而不是通過其它列間接依賴於主鍵 什麼是資料庫正規化 學習第一正規化的應用 什麼是正規化 一種規則,指導程式設計師建立表的規則 程式設計師...

資料庫設計三大正規化資料庫設計三大正規化

為了建立冗餘較小 結構合理的資料庫,設計資料庫時必須遵循一定的規則。在關係型資料庫中這種規則就稱為正規化。正規化是符合某一種設計要求的總結。要想設計乙個結構合理的關係型資料庫,必須滿足一定的正規化。在實際開發中最為常見的設計正規化有三個 1 第一正規化 確保每列保持原子性 第一正規化是最基本的正規化...

資料庫設計 三正規化

建立冗餘小,結構合理的資料庫,設計資料庫時必須准許你一定的規則,在關聯式資料庫中的這種規則就成為正規化.是要符合某一種設計要求的總結 要想設計乙個合理的關係資料型資料庫庫,就必須滿足一定的正規化 也是最基本的正規化.如果資料庫表中的所有字段值是都不可分解的原子值.例如 使用者資訊表中.但是這個並不是...