




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、PAGE7數據庫原理實驗報告題目:實驗五 安全性及事務操作學號:成績班級: 計算12日期:姓名:指導老師:林穎賢一、實驗目的:1、掌握SQL Server的安全機制; 2、掌握服務器的安全性的管理;3、掌握數據庫用戶的管理;4、掌握權限的管理。二、實驗使用環境:Windows 7 x64、SQL Server 2005三、實驗內容與完成情況:1、安全性綜合實驗1)設計安全機制使得用戶“test”只能查詢采購部門的職工。 sp_addlogin test,123execute sp_grantdbaccess test,wangmingcreate view V_empasselect * fr
2、om Employeeswhere Emp_depart=采購部grant select on V_emp to wangmingselect * from V_emp2)設計角色“Employees”,可以查看“職工”的職工號與姓名。并將用戶“test”作為成員加入角色“Employees”, 這樣用戶“test”只能查看“職工”的職工號與姓名。 exec sp_addrole employeesp_addrolemember employee,wangmingcreate view V_Role_Empasselect Emp_no,Emp_name from Employeesgrant
3、 select on V_Role_Emp to employeeselect * from V_Role_Emp3)請進行安全設置,用戶李建國師擁有以下權力:他要能查進貨表中的信息,并擁有對自已進貨的信息修改的權限,其它表的信息無權查看。sp_addlogin test1,123exec sp_grantdbaccess test1,李建國create view V_Liasselect * from Purchase where Emp_no in(select Emp_no from employees where Emp_name=李建國)grant select,update on
4、V_Li to 李建國grant select on Purchase to 李建國4)如何使得采購部門的員工都具有這樣的權限:能查看進貨表的信息,并擁有對自已采購信息的修改,其它的信息無權查看。(要求:編寫存儲過程proc_stu_grant,其作用:輸入參數為員工姓名,從進貨表中查找該員工所進貨的產品,如果沒有則返回,有的話則相應的在login表中添加賬號和密碼。并且,創建相應的登錄賬號和數據庫用戶)create proc proc_emp_grant Emp_name nvarchar(10)asbegindeclare sqlstr varchar(255)declare sqlvie
5、w varchar(14)if exists (select Pur_no from Purchase where Emp_no in (select Emp_no from Employees where Emp_name=Emp_name) begin set sqlview=Emp_name+_view set sqlstr=create view +sqlview+ as select * from Purchase where Emp_no in(select Emp_no from employees where Emp_name=+Emp_name+) exec(sqlstr)
6、exec sp_addlogin Emp_name,123456 exec sp_grantdbaccess Emp_name,Emp_name set sqlstr=grant select on Purchase to +Emp_name exec(sqlstr) set sqlstr=grant select,update on +sqlview+ to +Emp_name exec(sqlstr) endelse print沒有該員工的進貨信息!endexec proc_emp_grant 趙明exec proc_emp_grant 趙哈哈5)銀行轉賬問題CREATE TABLE ba
7、nk -創建賬戶表,存放用戶的賬戶信息( customerName CHAR(10), -顧客姓名 currentMoney MONEY -當前余額)GO-添加約束:根據銀行規定,賬戶余額不能少于1元,否則視為銷戶 ALTER TABLE bank ADD CONSTRAINT CK_currentMoney CHECK(currentMoney=1)GO-張三開戶,開戶金額為1000元 ;李四開戶,開戶金額1元 INSERT INTO bank(customerName,currentMoney) VALUES(張三,1000)INSERT INTO bank(customerName,cu
8、rrentMoney) VALUES(李四,1)寫出用事務解決銀行轉賬的存儲過程:create table bank( customerName char(10), currentMoney money)alter table bank add constraint ck_currentMoney check(currentMoney=1)insert into bank(customerName,currentMoney) values (張三,1000)insert into bank(customerName,currentMoney) values (李四,1)select * fro
9、m bankcreate proc proc_banksend char(10),receive char(10),money moneyasbegindeclare xianyou moneyselect xianyou=currentMoney from bank where customerName=sendif(xianyou-money)0) begin begin tran fail update bank set currentMoney=currentMoney-money where customerName=send update bank set currentMoney
10、=currentMoney+money where customerName=receive print轉賬失敗! rollback tran fail endelse begin update bank set currentMoney=currentMoney-money where customerName=send update bank set currentMoney=currentMoney+money where customerName=receive print轉賬成功! endendexec proc_bank 張三,李四,500四、出現的的問題及解決方案1、問題:刪除用戶時提示異常。解決方案:在刪除用戶時,先刪除對應的構架,再刪除對應的用戶。2、問題:操作不在對應數據庫。解決方案:執行代碼前,養成良好習慣,先使用use命令,切換到指定數據庫。3、問題:begin與end經常沒有一一對應。解決方案:在代碼排版上縮進一致,便
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 設備自主安全管理制度
- 設施維護保養管理制度
- 設計單位勘察管理制度
- 評估公司行政管理制度
- 診所前臺登記管理制度
- 診所藥品采購管理制度
- 財務部門進出管理制度
- 財政獎勵項目管理制度
- 貨物托運窗口管理制度
- 貨車裝貨排隊管理制度
- 2023年醫學高級職稱-中醫肛腸(醫學高級)考試歷年高頻考點試題含答案
- 體外循環管理
- 爬架拆除技術交底
- 2023小學數學教師選調進城考試備考試題及答案(10套)
- pergeos軟件教程評價許可介紹
- 冷凍食品凍壞處理應急預案
- 鐵路專用線施工組織
- 三明市人力資源和社會保障局關于2023年公開招考聘用緊缺急需專業工作人員模擬備考預測(共1000題含答案解析)綜合試卷
- 計算機系統結構智慧樹知到答案章節測試2023年同濟大學
- 自主招生的面試技巧
- 鄉土景觀研究智慧樹知到答案章節測試2023年長安大學
評論
0/150
提交評論