




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、南昌航空大學信息工程學院 數據庫原理 課程實驗報告 實驗名稱: 學生成績信息管理系統實驗時間: 2010年月2日指導教師: 班 級 : 學 號 : 姓 名 : 成 績 : 一、實驗目的(1) 通過完成從用戶需求分析、系統概要設計、系統詳細設計以及數據庫的SQL操作具體實現等全過程,把前面的各個實驗更好地綜合起來.(2) 進一步理解和掌握教材中的相關內容。(3) 掌握分析和設計一個大型數據庫系統的基本思路與方法。二、 實驗要求1. 獨立完成該系統的數據庫設計。2. 用SQL實現數據庫的設計,并在MS SQL Server上調試通過。3. 寫出查詢、更新以及建立觸發器SQL語句和執行結果。4. 掌
2、握報表的使用。三、實驗內容綜合前面各章內容設計并調試一學生成績管理系統,Delphi作為前臺開發工具,SQL Server完成后臺數據庫存管理。創建學生成績的統計(包括求班級各科成績的平均分);并實現對各科成績等的錄入、修改、刪除、查詢等功能;實現學生成績的統計(包括求班級各科成績的平均分);并實現對各科成績的排序。四、實驗代碼及功能注釋用戶登陸界面實驗程序:procedure TForm1.Button1Click(Sender: TObject);用戶登陸var ret:integer;beginadoconnection1.Open;with ADOStoredProc1 dobegin
3、Close;ProcedureName:='proc_login'Parameters.Clear;Parameters.Refresh;Parameters.ParamByName('username').Value:= Edit1.text;Parameters.ParamByName('password').Value:= Edit2.text;ExecProc;ret:= Parameters.ParamByName('return_value').Value;end;if ret=1 then /用戶名密碼匹配begin
4、showmessage('登陸成功');form3.show;endelseshowmessage('你不是用戶,請注冊');end ;procedure TForm1.Button2Click(Sender: TObject);若不是用戶,觸發用戶登陸界面顯示beginform2.show;end;procedure TForm1.Button3Click(Sender: TObject);退出該管理系統beginform1.Close;end;說明:在這里,使用了adostoredproc1控件和adoconnection1控件,它們的connections
5、tring屬性都要與所設計的數據庫相連,在查詢分析器中,要運行存儲過程如下:CREATE procedure proc_loginusername varchar(20),password varchar(20)asdeclare result intselect result=count(*) from users where username=username and passwords=passwordif result=0return 0return 1GO用戶注冊界面實驗程序:procedure TForm2.Button1Click(Sender: TObject);新用戶注冊be
6、gin adoquery1.close; adoquery1.sql.clear; adoquery1.sql.add('insert into users(username,passwords,核對密碼,性別,出生年月,聯系地址,聯系電話,郵政編碼,電子郵箱)'+'values(:1,:2,:3,:4,:5,:6,:7,:8,:9)'); adoquery1.parameters.parambyname('1').value:=''+edit1.text+'' adoquery1.parameters.param
7、byname('2').value:=''+edit2.text+'' adoquery1.parameters.parambyname('3').value:=''+edit3.text+'' adoquery1.parameters.parambyname('4').value:=''+combobox1.text+'' adoquery1.parameters.parambyname('5').value:=''+
8、combobox1.text+' '+combobox1.text+'' adoquery1.parameters.parambyname('6').value:=''+edit4.text+'' adoquery1.parameters.parambyname('7').value:=''+edit5.text+'' adoquery1.parameters.parambyname('8').value:=''+edit6.text+
9、'' adoquery1.parameters.parambyname('9').value:=''+edit7.text+'' adoquery1.execsql;end;說明:在該數據庫中,建了一個名為users的用戶表,存儲用戶的信息。只有是用戶在登陸時,才能進入主界面,當不是用戶在登陸時,必須先進行新用戶注冊,才能進入主系統。 系統主界面學生基本信息查詢精確查詢程序:procedure TForm3.Button1Click(Sender: TObject);beginwith adoquery1 dobegin if r
10、adiobutton1.Checked then /通過單選按鈕的選擇來判斷是要進行精確查詢還是模糊查詢 begin adoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add('select * from 學生表 where 學號='''+edit1.text+'''' ); adoquery1.Open; end;end;說明:由于學生表中,學號為主鍵,因此要查此表中學生基本信息,只要輸入主鍵值即可得一條記錄,即實現精確查詢。模糊查詢程序:procedure TForm3
11、.Button3Click(Sender: TObject);begin with adoquery1 do begin if radiobutton2.Checked then begin if (edit2.Text <>'')or (edit3.Text <>'')or(edit4.Text <>'')or(edit5.Text <>'') or(edit6.Text <>'')then begin adoquery1.Close; adoquery
12、1.SQL.Clear; adoquery1.SQL.Add('select * from 學生表'); adoquery1.SQL.Add('where(學號 like '''+'%'+edit2.text+'%'+''')'); adoquery1.SQL.Add('or(姓名 like '''+'%'+edit3.text+'%'+''')'); adoquery1.SQL.Add(
13、'or(所在系別 like '''+'%'+edit4.text+'%'+''')'); adoquery1.SQL.Add('or(所在專業 like '''+'%'+edit5.text+'%'+''')'); adoquery1.SQL.Add('or(所在班級 like '''+'%'+edit6.text+'%'+''
14、;')'); adoquery1.Open ; end else begin application.MessageBox('沒有查詢條件','提示',mb_ok); exit; end; end; end;end;說明:當輸入的信息不是主鍵時,由于滿足該輸入條件的記錄可能不只一個,因此得到的是一個模糊查詢的結果。學生成績查詢方法與學生基本信息查詢一致。學生基本信息錄入實驗程序:procedure TForm4.Button1Click(Sender: TObject);begin adoquery1.close; adoquery1.sql.c
15、lear; adoquery1.sql.add('insert into 學生表(學號,姓名,民族,出生年月,籍貫,性別,所在系別,所在專業,所在班級,政治面貌,家庭住址,郵政編碼,聯系電話)'+'values(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'); adoquery1.parameters.parambyname('1').value:=''+edit1.text+'' adoquery1.parameters.parambyname('2')
16、.value:=''+edit2.text+'' adoquery1.parameters.parambyname('3').value:=''+edit3.text+'' adoquery1.parameters.parambyname('4').value:=''+combobox1.text+' '+combobox2.text+'' adoquery1.parameters.parambyname('5').value:=
17、9;'+edit4.text+'' adoquery1.parameters.parambyname('6').value:=''+combobox3.text+'' adoquery1.parameters.parambyname('7').value:=''+combobox4.text+'' adoquery1.parameters.parambyname('8').value:=''+edit5.text+'' adoq
18、uery1.parameters.parambyname('9').value:=''+edit6.text+'' adoquery1.parameters.parambyname('10').value:=''+edit7.text+'' adoquery1.parameters.parambyname('11').value:=''+edit8.text+'' adoquery1.parameters.parambyname('12'
19、;).value:=''+edit9.text+'' adoquery1.parameters.parambyname('13').value:=''+edit10.text+'' adoquery1.execsql;end;在SQL Server中查看錄入結果錄入前:錄入后:說明:從錄入前與錄入后表的比較看到,實現了學號為aaa學生基本信息的錄入。求學生平均成績、成績排序并顯示實驗程序:procedure TForm3.Button4Click(Sender: TObject);begin with adoque
20、ry1 dobegin if radiobutton3.Checked then與學生基本信息查詢一樣,這里為成績精確查詢 beginadoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add('select * from 成績信息表 where 學號='''+edit9.text+'''' ); adoquery1.Open; end; if radiobutton4.Checked then與學生基本信息查詢一樣,這里為成績模糊查詢 begin if (edit10.te
21、xt <>'')or (edit11.Text <>'')or(edit12.Text <>'')or(edit13.Text <>'') or(edit14.Text <>'')then begin adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select * from 成績信息表'); adoquery1.SQL.Add('where(學號 like '
22、;''+'%'+edit10.text+'%'+''')'); adoquery1.SQL.Add('or(姓名 like '''+'%'+edit11.text+'%'+''')'); adoquery1.SQL.Add('or(所在系別 like '''+'%'+edit12.text+'%'+''')'); adoque
23、ry1.SQL.Add('or(所在專業 like '''+'%'+edit13.text+'%'+''')'); adoquery1.SQL.Add('or(所在班級 like '''+'%'+edit14.text+'%'+''')'); adoquery1.Open ; end else begin application.MessageBox('沒有查詢條件','提示
24、9;,mb_ok); exit; end; end; if radiobutton9.Checked then求每個學生的課程平均成績 begin adoquery1.Close ; sql.Clear ; sql.Add('select 學號,姓名,AVG(成績) as 平均成績 from 成績信息表 where 所在班級=''070413'' group by 學號,姓名'); adoquery1.Open ; end; if radiobutton11.Checked then將學生成績按從低到高排序 begin adoquery1.Clo
25、se ; sql.Clear ; sql.Add('select 學號,姓名,avg(成績) as 平均成績 from 成績信息表 group by 學號,姓名 order by 平均成績'); adoquery1.open; end;end;end;求平均成績界面與平均成績排序后界面:說明:使用到了數據庫的自帶函數avg() 來求平均成績,按平均成績排序時,只要在已經做好的平均成績顯示程序上加上order by 語句即可。學生基本信息刪除與修改實驗程序:procedure TForm3.Button6Click(Sender: TObject);begin with adoq
26、uery1 do begin if radiobutton7.Checked then begin adoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add('update 學生表 set '+combobox1.text+'='''+edit19.text+''''); /edit19 編輯框用來輸入要更改的字段名 adoquery1.SQL.Add('where 學號='''+edit18.text+''''); adoquery1.execsql; end; if radiobutton8.Checked then begin a
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高端汽車維修中心場地租賃及維修技術引進合同
- 不動產抵押擔保房地產開發合同
- 餐飲店面租賃及品牌升級改造合同
- 車輛安全責任事故調查與處理協議
- 產業園區廠房物業安全防范與應急處理合同
- 餐飲品牌區域代理權授權合同范本
- 生態旅游度假區租賃承租合同
- 城市綜合體餐飲業態承包協議書模板
- 餐飲店店長職位競聘與職業規劃合同
- 體育健身園區場地合作開發與經營協議書
- CNC機加工作業指導書
- HALCON編程基礎與工程應用全書ppt課件匯總(完整版)
- 冀教版小學美術六年級下冊教案
- 《一級學科下屬專業證明模板》
- 信陽市平橋區農村土地承包經營權轉包
- 《城市軌道交通通風與空調系統》教學課件—07地鐵通風空調概述
- Stein-膀胱癌淋巴清掃資料課件
- 小柳樹和小棗樹(1)
- 市場營銷學期末復習題知識分享
- 化學常用單詞匯總
- 大客戶銷售實戰技巧PPT
評論
0/150
提交評論