【文章內(nèi)容簡介】
。,39。歇業(yè) 39。)) 4) dish ① d_id, d_name, d_price, d_pid, d_total not null, ② d_remain int not null check (d_remain=0), 5) ord ① o_id, o_cadd not null, ② o_num int not null check (o_num0), ③ o_state varchar(15) check (o_state in(39。正常 39。,39。取消 39。)) 6) manager_client m_c_operation check (m_c_operation in(39。更新 39。,39。增加 39。,39。刪除 39。)) 7) manager_provider m_c_operation check (m_c_operation in(39。允許注冊 39。,39。注銷賬戶 39。) ) 1) 自動(dòng)更新時(shí)間: create trigger o_o_time on ord for insert as begin declare @oid int select @oid=o_id from inserted if exists(select*from ord where =@oid and is not null) update ord set o_time=(select getdate() as today) end 2) 對 d_remain 的觸發(fā)器 create trigger o_o_remain on ord for insert as begin declare @oid int select @oid=o_id from inserted if exists(select*from ord where o_id=@oid and o_id is not null) declare @did int select @did=o_did from ord where o_id=@oid declare @onum int select @onum=o_num from ord where o_id=@oid update dish set d_remain=d_remain@onum where d_id=@did end 3) 評價(jià)度增加 create trigger o_o_lev on ord for insert as begin declare @oid int select @oid=o_id from inserted if exists(select*from ord where o_id=@oid and o_id is not null) declare @pid varchar(9) select @pid=o_pid from ord where o_id=@oid update provider set p_lev=p_lev+1 where p_id=@pid update ord set o_state=39。正常 39。 where o_id=@oid end 安全性設(shè)計(jì) 、用戶、授權(quán) 1)客戶(舉例) CREATE LOGIN c20212511 WITH PASSWORD = 39。12345639。 create user buyijie for login c20212511。 grant connect to buyijie。 create role c。 grant select on provider to c。 grant select on dish to c。 grant update on dish(d_remain) to c。 grant select,insert on ord to c。 grant update on client to c。 exec sp_addrolemember 39。c39。,39。buyijie39。 2)商店(舉例) CREATE LOGIN p20211001 WITH PASSWORD = 39。wuqilong39。 create user 東北酒家 for login p20211001。 grant connect to 東北酒 家 。 create role p。 grant select,delete,insert on dish to p。 grant update on dish(d_name,d_price,d_discount,d_total) to p。 grant select on provider to p。 grant update on provider(p_name,p_tel,p_add,p_state) to p。 exec sp_addrolemember 39。p39。,39。東北酒家 39。 3) 管理員 管理員進(jìn)行后 臺管理,具有所有權(quán)限。 1) 消費(fèi)記錄 :用戶名字,菜名,單價(jià),打折,商店,時(shí)間,數(shù)量 create view c_ord(c_name,d_name,d_price,d_discount,p_name,o_time,o_num) as select c_name,d_name,d_price,d_discount,p_name,o_time,o_num from client,provider,dish,ord where = and = and = with check option。 2) 用戶查詢商店及菜 :商店信息與菜的信息 create view p_d(p_name,p_lev,p_state,p_tel,d_name,d_price,d_discount,d_remain) as select p_name,p_lev,p_state,p_tel,d_name,d_price,d_discount,d_remain from provider,dish where = with check option。 3) 商店查詢自己的菜品 create view p_o_d(p_name,d_id,d_name,d_price,d_discount,d_remain) as select p_name,d_id,d_name,d_price,d_discount,d_remain from provider,dish where = with check option。 4) 商店生成訂單 視圖 create view c_p_d(c_name,c_tel,d_name,d_price,d_discount,o_num,o_cadd) as select c_name,c_tel,d_name,d_price,d_discount,o_num,o_cadd from client,dish,ord where = and = with check option。 其他設(shè)計(jì) 對于 dish 表及 ord 表,設(shè)計(jì)在插入元祖是主鍵自增。若下一份訂單時(shí),讓客戶自己選擇主碼,可能會(huì)發(fā)生沖突;同樣也不符合實(shí)際情況 ① o_id int identity(10000001,1) ② d_id int identity(1378001,1) 設(shè)計(jì) 在每天的 0:00:00 執(zhí)行更新數(shù)據(jù)庫中 d_remain=d_total 五、數(shù)據(jù)庫實(shí)現(xiàn) 據(jù)庫的建立 啟動(dòng)服務(wù)管理器,打開查詢分析器,在調(diào)試程序窗口輸入下列語句: Create database database_zbg On ( name= zbg_data, Filename=39。 E:\dbdesign\ 39。, Size=10mb Maxsize=500mb, Filegrowth=5mb)