餐厅数据库设计Word文档下载推荐.docx
《餐厅数据库设计Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《餐厅数据库设计Word文档下载推荐.docx(11页珍藏版)》请在冰豆网上搜索。
CustomerInfo
客人信息表
FoodList
菜单信息表
FoodInfo
菜肴信息表
ChargeInfo
收银信息表
AccountInfo
账目信息表
OrderInfo
点菜信息表
C_C_A
客人、收银单、账目对应关系
PriceInfo
价格信息表
客人信息表CustomerInfo
描述
字段
类型
客人编号
Cusno
Int
桌号
Tableno
shortint
人数
Cusnum
客人类型
Ctype
char(4)
菜单信息表FoodList
菜单编号
Mno
菜肴编号
Fno
smallint
份数
Fnum
smalltint
口味
Ftaste
Char(4)
菜肴信息表FoodInfo
菜名
Fname
varchar(20)
菜肴种类
Fkind
收银信息表ChargeInfo
收银单编号
Chargeno
应收金额
Spay
int
折扣
Discount
实收金额
Rpay
账目信息表AccountInfo
账目编号
Accountno
消费金额
Pay
客户类型
点菜信息表OrderInfo
客人、收银单、账目对应关系表C_C_A
Acountno
价格信息表PriceInfo
类型
价格
Price
创建数据库:
createdatabaseinn;
创建表:
创建表CustomerInfo:
createtableCustomerInfo(
Cusnointprimarykey,
Tablenosmallintnotnull,
Cusnumsmallintnotnull,
Custypechar(4)notnull,
check(Custype='
普通'
orCustype='
VIP'
),
);
创建表FoodInfo:
createtableFoodInfo(
Fnamevarchar(20)primarykey,
Fkindchar(10)notnull,
创建表ChargeInfo:
createtableChargeInfo(
Chargenointprimarykey,
Spayint,
Discountint,
Rpayint
创建表AccountInfo:
createtableAccountInfo(
Accountnointprimarykey,
Payint,
Ctypechar(4)
创建表C_C_A:
createtableC_C_A(
Cusnointprimarykey,
Chargenointnotnull,
Accountnointnotnull
创建表PriceInfo:
createtablePriceInfo(
Fnosmallintprimarykey,
Fnamevarchar(20)notnull,
Pricesmallintnotnull
创建表FoodList:
createtableFoodList(
Mnoint,
Fnosmallint,
Fnumsmallintnotnull,
Ftastechar(4),
primarykey(Mno,Fno),
foreignkey(Fno)referencesPriceInfo(Fno)
创建表OrderInfo:
createtableOrderInfo(
Cusnoint,
Mnoint,
primarykey(Cusno,Mno),
foreignkey(Cusno)referencesCustomerInfo(Cusno)
四、物理结构设计
创建索引:
createindexindex_PriceInfoonPriceInfo(Fno);
createindexindex_FoodListonFoodList(Mno);
createindexindex_OrderInfoonOrderInfo(Mno);
createindexindex_FoodInfoonFoodInfo(Fname);
createindexindex_CustomerInfoonCustomerInfo(Cusno);
createindexindex_ChargeInfoonChargeInfo(Chargeno);
createindexindex_C_C_AonC_C_A(Cusno);
createindexindex_AccountInfoonAccountInfo(Accountno);
创建视图:
createviewKitchen
as
selectMno,Fname,Fnum,Ftaste
fromFoodList,PriceInfo
createviewDelivery
as
selectTableno,Fname,Fnum,Cusnum
fromFoodList,CustomerInfo,OrderInfo,PriceInfo
whereFoodList.Mno=OrderInfo.MnoandOrderInfo.Cusno=
CustomerInfo.CusnoandPriceInfo.Fno=FoodList.Fno
五、数据库实施
1、插入数据:
插入数据到表FoodInfo:
insertintoFoodInfovalues('
干锅千页豆腐'
'
推荐'
insertintoFoodInfovalues('
手撕包菜'
素菜'
水煮鱼片'
荤菜'
香干回锅肉'
油淋茄子'
蒜苗牛柳'
鱼香肉丝'
糖醋小排'
酸辣土豆丝'
宫爆鸡丁'
红烧鸡块'
冬瓜咸排汤'
汤类'
蕃茄蛋汤'
紫菜蛋汤'
土豆牛肉'
凉拌皮蛋'
凉菜'
凉拌毛豆'
插入数据到表PriceInfo:
insertintoPriceInfovalues(001,'
16);
insertintoPriceInfovalues(002,'
6);
insertintoPriceInfovalues(003,'
15);
insertintoPriceInfovalues(004,'
10);
insertintoPriceInfovalues(005,'
insertintoPriceInfovalues(006,'
18);
insertintoPriceInfovalues(007,'
insertintoPriceInfovalues(008,'
22);
insertintoPriceInfovalues(009,'
5);
insertintoPriceInfovalues(010,'
12);
insertintoPriceInfovalues(011,'
insertintoPriceInfovalues(012,'
8);
insertintoPriceInfovalues(013,'
蕃茄蛋汤'
insertintoPriceInfovalues(014,'
insertintoPriceInfovalues(015,'
24);
insertintoPriceInfovalues(016,'
insertintoPriceInfovalues(017,'
2、创建用户、角色
创建用户:
选择目的数据库中的安全性,右击安全性中的用户,选择新建用户,在弹出的数据库用户-新建对话框中输入用户名和登录名Delivery,单击确定。
重复上述操作完成对用户Kitchen、Admin、Waiter的创建。
创建角色:
选择目的数据库中的安全性,右击安全性中的角色,选择新建中的新建数据库角色,出现数据库角色-新建对话框,输入角色名,并选择所有者,在此角色的成员中单击添加选择角色成员,单击确定完成角色创建。
3、对用户授权
grantselectonKitchentoKitchen;
grantupdateonFoodListtoKitchen;
grantselectonDeliverytoDelivery;
grantupdateonFoodListtoDelivery;
grantallprivilegesonAccountInfotoAdmin
grantallprivilegesonC_C_AtoAdmin
grantallprivilegesonChargeInfotoAdmin
grantallprivilegesonCustomerInfotoAdmin
grantallprivilegesonFoodInfotoAdmin
grantallprivilegesonFoodListtoAdmin
grantallprivilegesonOrderInfotoAdmin
grantallprivilegesonPriceInfotoAdmin
grantallprivilegesonKitchentoAdmin
grantallprivilegesonDeliverytoAdmin
grantallprivilegesonFoodlisttoWaiter
grantallprivilegesonCustomerInfotoWaiter
grantallprivilegesonChargeInfotoWaiter
4、创建触发器
在表FoodInfo中创建触发器:
createtriggerDELETE_FOODINFO
onFoodInfo
afterdelete
as
begin
deletefromPriceInfowherePriceInfo.Fname=Fname
setnocounton;
end
go
六、数据库运行和维护
1、备份数据库:
在数据库文件选项中选择要备份的数据库inn,右键单击,选择任务-备份选项出现数据库备份对话框,备份类型选择完整,在目标项中选择添加,弹出选择备份目标,在磁盘上的目标中选择备份数据库的目标文件夹,选择好路径后,将文件名取为inn,点击确定后,完成备份。
2、还原数据库:
在数据库文件选项中单击右键,选择还原数据库,弹出还原数据库对话框,在目标数据库中选择要还原的数据库inn,在还原的源项中选择源设备,在弹出的指定备份中选择备份位置,选择已备份的文件后,单击确定,在选择用于还原的备份集中选定要还原的文件,单击确定,完成数据库还原。
四、实验结论
通过此次实验,加深对数据完整性的理解,学会创建和使用触发器。
加深对数据安全性的理解,并掌握SQLServer中有关用户,角色及操作权限的管理方法。
学会根据数据库系统设计的基本步骤,完成某一具体数据库系统的需求分析、概念结构设计、逻辑结构设计、物理结构设计、数据库实施和数据库运行维护等功能。