資料表設計思想,ER圖及三正規化
資料表設計思想
設計流程
需求分析:根據使用者的需求,分析出需要記錄的資料
需求設計:根據分析出的資料,設計E-R模型圖
詳細設計:將E-R模型圖轉換成資料表
三大正規化:使用資料庫三大正規化的設計思想對資料表進行稽核
E-R模型圖
概念:Entity-Relationship,實體關係圖
組成元素:
舉例,將下面三張表用E-R模型圖表示出來
三大正規化
概念:三大正規化是資料庫的一種設計規範,主要用來檢查我們的資料庫是否存在冗餘資料。
第一正規化:每一列都具有原子性,也就是不能再分割
第二正規化:要求每一個表,只描述一件事情
第三正規化:要求表中不存在冗餘欄位
create table Score
(
sId int primary key auto_increment,
studentId int not null,
english float,
math float
)
create table teacher
(
tId int auto_increment primary key,
tName varchar(50) not null,
tSex char(2),
tAge int,
tSalary decimal
)
create table Class
(
cId int auto_increment primary key,
cName nvarchar(50) not null,
cDesciption text
)
create table Student
(
SId int auto_increment primary key,
SName varchar(50),
SGender char(2) not null,
SAddress varchar(300),
SPhone varchar(100),
SAge int,
SBirthday datetime,
SCardId varchar(18) null,
SClassId int not null
)
資料表設計思想
設計流程
需求分析:根據使用者的需求,分析出需要記錄的資料
需求設計:根據分析出的資料,設計E-R模型圖
詳細設計:將E-R模型圖轉換成資料表
三大正規化:使用資料庫三大正規化的設計思想對資料表進行稽核
E-R模型圖
概念:Entity-Relationship,實體關係圖
組成元素:
舉例,將下面三張表用E-R模型圖表示出來
三大正規化
概念:三大正規化是資料庫的一種設計規範,主要用來檢查我們的資料庫是否存在冗餘資料。
第一正規化:每一列都具有原子性,也就是不能再分割
第二正規化:要求每一個表,只描述一件事情
第三正規化:要求表中不存在冗餘欄位
create table Score
(
sId int primary key auto_increment,
studentId int not null,
english float,
math float
)
create table teacher
(
tId int auto_increment primary key,
tName varchar(50) not null,
tSex char(2),
tAge int,
tSalary decimal
)
create table Class
(
cId int auto_increment primary key,
cName nvarchar(50) not null,
cDesciption text
)
create table Student
(
SId int auto_increment primary key,
SName varchar(50),
SGender char(2) not null,
SAddress varchar(300),
SPhone varchar(100),
SAge int,
SBirthday datetime,
SCardId varchar(18) null,
SClassId int not null
)