分析设计网上书店数据库,并画E-R图
? ? ? ? 分析并設(shè)計(jì)網(wǎng)上書店數(shù)據(jù)庫(kù),繪制E-R圖,網(wǎng)上書店具有如下功能:
1、會(huì)員的注冊(cè)、登錄
2、網(wǎng)上預(yù)訂圖書
3、圖書信息瀏覽
訓(xùn)練技能點(diǎn):
1、會(huì)將E-R圖轉(zhuǎn)換為表
2、理解數(shù)據(jù)規(guī)范化
4、將分析在SQL Server數(shù)據(jù)庫(kù)中實(shí)現(xiàn)具體的表
Sql server三范式的理解:
第一范式:數(shù)組的每個(gè)屬性只能包含一個(gè)值;
關(guān)系中的每個(gè)數(shù)組必須包含相同的數(shù)量的值;
關(guān)系中的每個(gè)數(shù)組一定不能相同。
第二范式:如果一個(gè)數(shù)據(jù)表已經(jīng)滿足第一范式,而且該數(shù)據(jù)表中的任何一個(gè)非主鍵字段的數(shù)值都依賴于該數(shù)據(jù)表的主鍵字段,那么該數(shù)據(jù)表滿足第二范式。
第三范式:如果一個(gè)數(shù)據(jù)表已經(jīng)滿足第二范式,而且該數(shù)據(jù)表中的任何兩個(gè)非主鍵字段的數(shù)值之間不存在函數(shù)信賴關(guān)系,那么該數(shù)據(jù)表滿足第三范式。
數(shù)據(jù)庫(kù)實(shí)體分析結(jié)果:
會(huì)員Users(會(huì)員編號(hào),昵稱,密碼,電子郵件,等級(jí))
等級(jí)UserGrade(等級(jí)編號(hào),等級(jí)名稱)
圖書訂單Orders(訂單編號(hào),會(huì)員編號(hào),書編號(hào),數(shù)量,總價(jià),預(yù)定日期)
書Books(書編號(hào),書名,作者,出版社編號(hào),單價(jià))
出版社Publishers(出版社,出版社名稱)
分析后繪制E-R圖如下:
用word把各實(shí)體關(guān)系圖轉(zhuǎn)化為表格;標(biāo)識(shí)主鍵,用紅色加粗字體把主鍵標(biāo)識(shí)出來(lái);需要在表之間體現(xiàn)實(shí)體之間的映射關(guān)系,即建立表的外鍵,用綠色加粗字體標(biāo)識(shí)外鍵
然后建立網(wǎng)上書店數(shù)據(jù)庫(kù)(Online_Bookstore)并插入部分?jǐn)?shù)據(jù)
use master create database Online_Bookstore on primary ( name='Online_Bookstore', filename='D:\Data\Online_Bookstore.mdf', size=10, maxsize=20, filegrowth=10% ) log on ( name='Online_Bookstore_log', filename='D:\Data\Online_Bookstore_log.ldf', size=1, maxsize=10, filegrowth=10% )use Online_Bookstore create table Users( UserID int primary key not null, UserName varchar(20) not null, Pwd varchar(10) null, Email varchar(40) null, GradeID int not null )create table Orders( OrderID int primary key not null, UserID int not null, BookID int not null, Number int not null, OrderDate datetime not null, OrderPrice money not null )create table Books( BookID int primary key not null, BookName varchar(20) not null, Author varchar(10) not null, PublisherID int not null, BookPrice money not null )create table UserGrade( GradeID int primary key not null, GradeName varchar(20) not null )create table Publishers( PublisherID int primary key not null, PublisherName varchar(20) not null )--創(chuàng)建約束 alter table Users add constraint fk_GradeID foreign key (GradeID) references UserGrade(GradeID) alter table Orders add constraint df_Number default 0 for Number alter table Orders add constraint df_OrderPrice default 0 for OrderPrice alter table Orders add constraint fk_UserID foreign key(UserID) references Users(UserID) alter table Orders add constraint fk_BookID foreign key(BookID) references Books(BookID) alter table Books add constraint fk_PublisherID foreign key(PublisherID) references Publishers(PublisherID)--插入數(shù)據(jù) insert into Users(UserID,UserName,Pwd,Email,GradeID) values(1001,'Mark','ss66##','cruo@126.com',2) insert into Users(UserID,UserName,Pwd,Email,GradeID) values(1002,'瑪麗','458712','mali@163.com',1) insert into Users(UserID,UserName,Pwd,Email,GradeID) values(1003,'Sunny','sunny008','Sunny008@hotmail.com',2) insert into Users(UserID,UserName,Pwd,Email,GradeID) values(1004,'驕陽(yáng)似火','upp8912','Hell80@topvip.com',2) insert into Users(UserID,UserName,Pwd,Email,GradeID) values(1005,'綠野萍蹤','lypz800*','Lypz008@sohu.com',3)insert into UserGrade(GradeID,GradeName) values(1,'普通會(huì)員') insert into UserGrade(GradeID,GradeName) values(2,'VIP會(huì)員') insert into UserGrade(GradeID,GradeName) values(3,'鉆石會(huì)員')建立數(shù)據(jù)庫(kù)關(guān)系圖:
如有錯(cuò)誤,還望指正 [抱拳]
總結(jié)
以上是生活随笔為你收集整理的分析设计网上书店数据库,并画E-R图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C++对象数组与对象指针
- 下一篇: 数据结构顺序表