BBS論壇數(shù)據(jù)庫設(shè)計開發(fā)_第1頁
BBS論壇數(shù)據(jù)庫設(shè)計開發(fā)_第2頁
BBS論壇數(shù)據(jù)庫設(shè)計開發(fā)_第3頁
BBS論壇數(shù)據(jù)庫設(shè)計開發(fā)_第4頁
BBS論壇數(shù)據(jù)庫設(shè)計開發(fā)_第5頁
已閱讀5頁,還剩20頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、. . . . 1 / 25理理工工大大學(xué)學(xué)華華夏夏學(xué)學(xué)院院課課程程設(shè)設(shè)計計報報告告書書課程名稱:課程名稱: 數(shù)據(jù)庫原理與應(yīng)用 題題 目目: BBS 論壇數(shù)據(jù)庫設(shè)計開發(fā) 系系 名:名:信息工程系 專業(yè)班級:專業(yè)班級: 計應(yīng) 2091 姓姓 名:名: 夢柯 學(xué)學(xué) 號:號:指導(dǎo)教師指導(dǎo)教師: : 春燕 20102010 年 7 7月 1 1 日. . . . 2 / 25課程設(shè)計任務(wù)書學(xué)生: 夢柯 專業(yè)班級: 計應(yīng) 2091 指導(dǎo)教師: 春燕 工作單位: 信息工程系 設(shè)計題目:BBS 論壇數(shù)據(jù)庫設(shè)計開發(fā)要求完成的主要任務(wù):(包括課程設(shè)計工作量與其技術(shù)要求,以與說明書撰寫等具體要求)1 創(chuàng)建數(shù)據(jù)庫

2、BBS,數(shù)據(jù)表,并建立主外鍵、約束、建立表測試數(shù)據(jù);2 創(chuàng)建視圖3 實現(xiàn)以下功能:(1)簡單查詢(2)連接查詢;(3)嵌套查詢(4)創(chuàng)建觸發(fā)器(5)創(chuàng)建存儲過程設(shè)計報告撰寫格式要求:設(shè)計報告撰寫格式要求:1、明確課程設(shè)計的目的和重要性,認(rèn)真領(lǐng)會課程設(shè)計的題目,讀懂課程設(shè)計指導(dǎo)書的要求,學(xué)會設(shè)計的基本方法與步驟,學(xué)會如何運用前修知識與收集、歸納相關(guān)資料解決具體問題的方法。嚴(yán)格要求自己,要獨立思考,按時、獨立完成課程設(shè)計任務(wù)。2、設(shè)計報告:要求層次清楚、整潔規(guī)、不得相互抄襲,凡正文容有整段完全一樣者一律以抄襲論處。設(shè)計報告正文字?jǐn)?shù)不少于 0.2 萬字(不包括附錄)時間安排:時間安排:消化資料、系統(tǒng)

3、調(diào)查 1 天系統(tǒng)分析、總體設(shè)計,實施計劃、撰寫報告 3 天演示、驗收 1 天指 導(dǎo) 教 師 簽字:2011 年 6 月 25 日系 主 任 簽 字: 2011 年 6 月 26 日. . . . 3 / 25目錄目錄1.1.問題描述問題描述 4 41.11.1 背景背景 4 41.21.2 數(shù)據(jù)需求數(shù)據(jù)需求 4 4. .方案圖表設(shè)計方案圖表設(shè)計 5 52.12.1 E-RE-R 圖圖 5 52.22.2 數(shù)據(jù)字典數(shù)據(jù)字典 7 72.42.4 關(guān)系圖:關(guān)系圖:8 83.3.數(shù)據(jù)庫源代碼數(shù)據(jù)庫源代碼 9 93.13.1 數(shù)據(jù)庫建立數(shù)據(jù)庫建立 9 93.23.2 數(shù)據(jù)初始化數(shù)據(jù)初始化錯誤!未定義書簽

4、。4.4.結(jié)果數(shù)據(jù)處理結(jié)果數(shù)據(jù)處理 14144.14.1 單表查詢單表查詢 14144.24.2 要求數(shù)據(jù)查詢要求數(shù)據(jù)查詢 15155.5.結(jié)束語結(jié)束語 2525. . . . 4 / 251.1.問題描述問題描述1.11.1 背景背景隨著 BBS 的出現(xiàn),人們的交流有了新的變化。在 BBS 里,人們之間的交流打破了空間、時間的限制。BBS 連人方便,可以通過 Internet 登錄,也可以通過網(wǎng)撥號登錄。BBS 站往往是由一些有志于此道的愛好看建立,對所有人都免費開放。而且,由于 BBS 的參與人眾多,因此各方面的話題都不乏熱心者。可以說,在 BBS 上可以找到任何你感興趣的話題。1.21.

5、2 數(shù)據(jù)需求數(shù)據(jù)需求BBS 論壇數(shù)據(jù)庫需要完成功能主要有:BBS 最主要的功能之一。包括各類的學(xué)術(shù)專題討論區(qū),疑難問題解答區(qū)和閑聊區(qū)等等。在這些信件區(qū)中,上站的用戶留下自己想要與別人交流的信件,如在各種軟件硬件的使用、天文、醫(yī)學(xué)、體育、游戲等等方面的心得和經(jīng)驗。這是 BBS 一個令用戶們心動的功能。一般的 BBS 站臺中,大多設(shè)有交流用的文件區(qū),里面依照不同的主題分區(qū)存放了為數(shù)不少的軟件,有的 BBS 站還設(shè)有CDROM 光碟區(qū),使得電腦玩家們對這個眼前的寶庫都趨之若鶩。眾多的共享軟件和免費軟件都可以通過 BBS 獲取得到,不僅使用戶得到合適的軟件,也使軟件開 BBS 對國 Shareware

6、 (共享軟件)的發(fā)展將起到不可替代的推動作用。國 BBS 主要提供的文件服務(wù)區(qū)主要有 BBS 建站、通信程序、網(wǎng)絡(luò)工具、Internet 程序、加解密工具、多媒體程序、電腦游戲、病毒防治、圖象、創(chuàng)作發(fā)表和用戶這是 BBS 最基本的功能了。一些有心的站長會在自己的站臺上擺出為數(shù)眾多的信息。如怎樣使用 BBS 、國 BBS 臺站介紹、某些熱門軟件的介紹、BBS 用戶統(tǒng)計資料等;用戶在生日時甚至?xí)盏秸鹃L的一封熱情洋溢的“賀電”,令您感受到 BBBS 還會自動統(tǒng)計出熱門話題排行榜,看看誰的文章受到的回應(yīng)最多線的 BBS 可以與其他同時上站的用戶做到即時的聯(lián)機(jī)交談。這種功能也有許多變化,如 ICQ 、

7、Chat、NetMeeting 等。有的只能進(jìn)行文字交談。. . . . 5 / 25. .方案圖表設(shè)計方案圖表設(shè)計2.1.1 用戶 E-R 圖用戶用戶密碼 用戶 Email 用戶生日 用戶性別 用戶等級 個人說明 用戶積分 用戶編號 用戶 XX 用戶狀態(tài) 注冊時間 圖 2.1 用戶 BBSUSER E-R 圖2.1.2 主貼 E-R 圖主貼用戶編號 回復(fù)次數(shù) 主帖表情 主帖標(biāo)題 主帖內(nèi)容 發(fā)帖時間 主帖編號 版塊編號 最后點擊時間 點擊次數(shù) 圖 2.2 用戶 BBSTOPIC E-R 圖2.1.3 板塊 E-R 圖. . . . 6 / 25板塊版塊名稱 版主編號 版塊說明 版塊點擊次數(shù) 版

8、塊編號 版塊主題數(shù) 圖 2.3 用戶 BBSSection E-R 圖2.1.4 回帖 E-R 圖回帖回復(fù)版塊編號 回復(fù)用戶編號 回復(fù)表情 回帖主題 回帖內(nèi)容 回帖時間 回復(fù)編號 回復(fù)帖子編號 回帖點擊次數(shù) 圖 2.4 用戶 BBSREPLY E-R 圖2.1.5 整體 E-R 圖. . . . 7 / 25 1 n 1 1 n n n n 1 1 n 1用戶主貼回帖板塊發(fā)表對應(yīng)發(fā)表管理包含包含圖 2.5 整體 E-R 圖2.22.2 數(shù)據(jù)字典數(shù)據(jù)字典表-1 BBSUsers 用戶信息表表中列名表中列名數(shù)據(jù)類型數(shù)據(jù)類型可否為空可否為空說明說明UIDUIDIntIntnotnot null(nu

9、ll(主鍵主鍵) )用戶編號用戶編號UNameUNamecharcharnotnot nullnull用戶用戶UPasswordUPassword charcharnotnot nullnull用戶密碼用戶密碼UEmailUEmailcharcharnotnot nullnull用戶用戶 EmailEmail UBirthdayUBirthdaydatetimedatetimenotnot nullnull用戶生日用戶生日 USexUSexbitbitnotnot nullnull用戶性別用戶性別 UClassUClass IntIntnotnot nullnull用戶等級用戶等級 UStat

10、ementUStatementvarcharvarcharnotnot nullnull用戶個人說明用戶個人說明 URegDateURegDate datetimedatetimenotnot nullnull用戶注冊時間用戶注冊時間 UStateUStatetinyinttinyintnotnot nullnull用戶狀態(tài)用戶狀態(tài) UPointUPoint ininnotnot nullnull用戶積分用戶積分 表-2BBSTopic 主貼信息表格表中列名表中列名數(shù)據(jù)類型數(shù)據(jù)類型可否為空可否為空說明說明TIDTIDIntIntnotnot null(null(主鍵主鍵) )主帖編號主帖編號

11、TSIDTSIDIntIntnotnot nullnull主帖版塊編號主帖版塊編號 TuidTuidIntIntnotnot nullnull主帖用戶編號主帖用戶編號 TReplyCountTReplyCountIntIntnotnot nullnull主帖回復(fù)次數(shù)主帖回復(fù)次數(shù) TEmotionTEmotion Char(10)Char(10)notnot nullnull主帖表情主帖表情 TTopicTTopic VarcharVarcharnotnot nullnull主帖標(biāo)題主帖標(biāo)題 . . . . 8 / 25TContentsTContentsTextTextnotnot nulln

12、ull主帖容主帖容 TTimeTTime DatetimeDatetimenotnot nullnull發(fā)帖時間發(fā)帖時間 TClickCountTClickCount IntIntnotnot nullnull主帖點擊次數(shù)主帖點擊次數(shù) TLastClickTTLastClickTDatetimeDatetimenotnot nullnull主帖最后點擊時間主帖最后點擊時間 表 2-3BBSSection 板塊信息表中列名表中列名數(shù)據(jù)類型數(shù)據(jù)類型可否為空可否為空說明說明sidsidIntIntNotNot nullnull( (主鍵主鍵) )版塊編號版塊編號 SNameSNamecharchar

13、NotNot nullnull版塊名稱版塊名稱 SMasterIDSMasterID IntIntNotNot nullnull版主編號版主編號 SStatementSStatementVarcharVarcharNotNot nullnull版塊說明版塊說明 SClickCountSClickCountIntIntNotNot nullnull版塊點擊次數(shù)版塊點擊次數(shù) STopicCountSTopicCountintintNotNot nullnull版塊主題數(shù)版塊主題數(shù) 表 2-4BBSReply 回帖信息表表中列名表中列名數(shù)據(jù)類型數(shù)據(jù)類型可否為空可否為空說明說明SIDSIDIntInt

14、NotNot null(null(主鍵主鍵) )版塊編號版塊編號 SnameSnameCharCharNotNot nullnull版塊名稱版塊名稱 SMasterIDSMasterIDIntIntNotNot nullnull版塊編號版塊編號 SStatementSStatementvarcharvarcharNotNot nullnull板塊說明板塊說明 SClickCountSClickCountIntIntNotNot nullnull版塊點擊次數(shù)版塊點擊次數(shù) STopicCountSTopicCountintintNotNot nullnull板塊主題數(shù)板塊主題數(shù)2.42.4 關(guān)系圖

15、:關(guān)系圖:圖.6 數(shù)據(jù)庫存表關(guān)系圖. . . . 9 / 253.3.數(shù)據(jù)庫源代碼數(shù)據(jù)庫源代碼3.13.1 數(shù)據(jù)庫建立數(shù)據(jù)庫建立3.1.13.1.1 創(chuàng)建數(shù)據(jù)庫創(chuàng)建數(shù)據(jù)庫-建庫,建表,添加約束建庫,建表,添加約束-插入測試數(shù)據(jù)插入測試數(shù)據(jù)-存在檢測存在檢測useuse mastermastergogoifif exists(select*fromexists(select*from sysdatabasessysdatabases wherewhere namename =BBS)=BBS)dropdrop databasedatabase bbsbbsgogo-建庫建庫createcreat

16、e databasedatabase BBSBBSonon primaryprimary( (namename = = BBS_data,BBS_data, -邏輯名邏輯名filenamefilename =d:BBS_data.mdf,=d:BBS_data.mdf, -物理文件物理文件sizesize = = 20MB,20MB, -初始大小初始大小filegrowth=10%,filegrowth=10%, -文件增長率文件增長率maxsizemaxsize = = 200MB200MB -初始大小初始大小) )loglog onon( (namename =bbs_log,=bbs_l

17、og, -邏輯名邏輯名filenamefilename =d:bbs_data.ldf,=d:bbs_data.ldf, -物理文件物理文件sizesize =10mb,=10mb, -初始大小初始大小filegrowthfilegrowth = = 10%,-10%,-文件增長率文件增長率maxsizemaxsize = = 100MB100MB -最大尺寸最大尺寸) )3.1.23.1.2 用戶信息表建立用戶信息表建立useuse BBSBBSgoif exists(select*from sysobjects where name =BBSUsers)drop table BBSUser

18、sgocreate table BBSUsers(Uid int constraint pk_Uid primary key,-用戶編號. . . . 10 / 25Uname char(8) not null, -用戶UPassword char(16) constraint df_UPassword default 888888,-用戶密碼UEmail char(20) not null constraint ck_Uemail check(Uemail like%.%),-用戶EMAILUBirthday datetime not null,-用戶生日Usex int constrain

19、t df_Usex default 1, -用戶性別UClass int constraint df_UClass default 1, -用戶等級UStatement varchar(150)not null, -用戶說明URegDate datetime not null default getdate(), -用戶注冊時間UState tinyint constraint df_UState default 1, -用戶狀態(tài) UPoint int constraint df_UPoint default 20 , -用戶積分 constraint ck_UPassword check(U

20、Password like _)3.1.33.1.3 創(chuàng)建主貼表創(chuàng)建主貼表if exists(select*from sysobjects where name =BBSTopic)drop table BBSTopicgocreate table BBSTopic(tid int constraint pk_tid primary key, -主貼編號tsid int not null, -主貼板塊編號tuid int not null, -主貼用戶編號treplycount int not null, -主貼回復(fù)次數(shù)temotion char(10) not null, -主貼表情TTop

21、ic varchar(16) not null CONSTRAINT ck_tt check(TTopic not like%), -主貼標(biāo)題TContents text not null, -主貼容TTime datetime not null default getdate() ,-發(fā)帖時間TClickCount int not null, -點擊次數(shù) TLastClickT datetime not null ,CONSTRAINT CK_TLC CHECK (TLastClickT=TTime) -主貼最后點擊時間 )3.1.43.1.4 回復(fù)表建立回復(fù)表建立if exists(sel

22、ect*from sysobjects where name =BBSReply)drop table BBSReplygocreate table BBSReply(RID int constraint pk_RID primary key,-回復(fù)編號 RTID int,-回復(fù)帖子編號 RSID int,-回復(fù)版塊編號 RUID int,-回復(fù)用戶編號 REmotion char(10),-回復(fù)表情 RTopic varchar(20),-回帖主題RContents text,-回帖容. . . . 11 / 25RTime datetime default getdate(),-回帖時間R

23、ClickCount int,-回帖點擊次數(shù))3.1.53.1.5 版塊信息表建立版塊信息表建立if exists(select*from sysobjects where name =BBSSection)drop table BBSSectiongocreate table BBSSection(SID int constraint pk_SID primary key,-版塊編號SName char(10),-版塊名稱 SMasterID int, -版主編號 SStatement varchar(80), -版塊說明 SClickCount int constraint df_SCli

24、ckCount default 0, -版塊點擊次數(shù) STopicCount int constraint df_STopicCount default 0 -版塊主題數(shù) 3.1.63.1.6 表之間的約束與聯(lián)系表之間的約束與聯(lián)系alteralter tabletable BBSTopicBBSTopicaddadd constraintconstraint fk1_BBSTopic_BBSUsersfk1_BBSTopic_BBSUsers foreignforeign key(tuid)key(tuid) referencesreferences BBSUsers(Uid)BBSUsers

25、(Uid) - - -一個用戶可以發(fā)表多篇主帖容一個用戶可以發(fā)表多篇主帖容alteralter tabletable BBSReplyBBSReplyaddadd constraintconstraint fk1_BBSReply_BBSTopicfk1_BBSReply_BBSTopic foreignforeign key(RTID)key(RTID) referencesreferences BBSTopic(TID)BBSTopic(TID) - - -一篇主帖能夠?qū)?yīng)多條回帖一篇主帖能夠?qū)?yīng)多條回帖alteralter tabletable BBSReplyBBSReplyaddad

26、d constraintconstraint fk1_BBSReply_BBSUsersfk1_BBSReply_BBSUsers foreignforeign key(RUID)key(RUID) referencesreferences BBSUsers(UID)BBSUsers(UID) -一個用戶可以發(fā)表多條回帖容一個用戶可以發(fā)表多條回帖容alteralter tabletable BBSTopicBBSTopicaddadd constraintconstraint fk1_BBSTopic_BBSSectionfk1_BBSTopic_BBSSection foreignforei

27、gn key(tsid)key(tsid) referencesreferences BBSSection(Sid)BBSSection(Sid) -一個版塊可以包含多篇主帖一個版塊可以包含多篇主帖alteralter tabletable BBSReplyBBSReplyaddadd constraintconstraint fk1_BBSReply_BBSSectionfk1_BBSReply_BBSSection foreignforeign key(RSID)key(RSID) referencesreferences BBSSection(Sid)BBSSection(Sid) -一

28、個版塊可以包含多篇回帖一個版塊可以包含多篇回帖alteralter tabletable BBSSectionBBSSectionaddadd constraintconstraint fk1_BBSSection_BBSUsersfk1_BBSSection_BBSUsers foreignforeign key(SMasterID)key(SMasterID) referencesreferences BBSUsers(Uid)BBSUsers(Uid) -一個用戶可以管理多個版塊一個用戶可以管理多個版塊3.2.13.2.1 將數(shù)據(jù)加入表將數(shù)據(jù)加入表 BBSUSERSBBSUSERS 中中

29、-插入數(shù)據(jù)插入數(shù)據(jù)insertinsertintointo BBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UStaBBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UState,UPoint)te,UPoint)values(1001values(1001 ,龍龍,123456,1990-12-12,1,ANGEL,2010-5-,123456,1990-12-12,1,ANGEL

30、,2010-5-7,2,)7,2,)insertinsertintointo BBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UStaBBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,USta. . . . 12 / 25te,UPoint)te,UPoint)values(1002values(1002 ,妄想者妄想者,654321,1980-7-1,2,ANGEL,2011-4-

31、,654321,1980-7-1,2,ANGEL,2011-4-7,2,4)7,2,4)insertinsertintointo BBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UStaBBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UState,UPoint)te,UPoint)values(1003values(1003 ,刺客刺客,158664,1997-1-03,2,ANG

32、EL,2009-5-,158664,1997-1-03,2,ANGEL,2009-5-7,2,3)7,2,3)insertinsertintointo BBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UStaBBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UState,UPoint)te,UPoint)values(1004values(1004 ,毀滅毀滅,175175,1992

33、-1-4,1,ANGEL,2008-5-,175175,1992-1-4,1,ANGEL,2008-5-4,2,2)4,2,2)insertinsertintointo BBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UStaBBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UState,UPoint)te,UPoint)values(1005values(1005 ,魔女魔女,19

34、8755,1994-1-4,1,ANGEL,2000-12-,198755,1994-1-4,1,ANGEL,2000-12-12,1,100)12,1,100)insertinsertintointo BBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UStaBBSUsers(uid,uname,upassword,uemail,UBirthday,USex,UClass,UStatement,URegDate,UState,UPoint)te,UPoint)values(1006val

35、ues(1006 ,魔王魔王,192445,1994-12-14,2,fdfs,2000-12-,192445,1994-12-14,2,fdfs,2000-12-12,1,97)12,1,97)3.2.23.2.2 將已有版塊數(shù)據(jù)加入將已有版塊數(shù)據(jù)加入 BBSBBSSection 表中表中-Sectioninsertinto BBSSection(SID,SName,SMasterID,SStatement,SClickCount,STopicCount)values(01 ,灌水懶,1006,說廢話的地方,5,5)insertinto BBSSection(SID,SName,SMaste

36、rID,SStatement,SClickCount,STopicCount)values(02 ,游戲廳,1005,說游戲的地方,4,5)3.2.33.2.3 將已有帖子信息加入將已有帖子信息加入 BBSTOPICBBSTOPIC 表中表中*/*/-topicinsertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2001 ,01,1006,1,.,我是魔王,DEVIL MAY CRY,2011-1-10,5,2011-6-24)

37、insertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents . . . . 13 / 25,TTime,TClickCount,TLastClickT)values(2002 ,01,1006,0,.,灌水來著,DEVIL MAY CRY,2011-4-10,4,2011-6-28)insertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2003 ,

38、01,1006,1,.,灌水來著 1,DEVIL MAY CRY,2011-1-10,3,2011-6-27)insertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2004 ,01,1006,0,.,灌水來著 2,DEVIL MAY CRY,2011-1-10,2,2011-6-26)insertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,T

39、Time,TClickCount,TLastClickT)values(2005 ,01,1006,1,.,灌水來著 3,DEVIL MAY CRY,2011-4-10,1,2011-6-24)insertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2011 ,02,1001,1,.,求助,請問。 。 。 。,2011-1-11,6,2011-6-29)insertinto BBSTopic(tid,TSID,TUID,TReply

40、Count,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2012 ,02,1002,0,.,討論,DN 好玩不?,2011-1-11,7,2011-6-23)insertinto BBSTopic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2013,02,1003,0,.,研究,那個。 。 。 。,2011-2-11,8,2011-6-23)insertinto BBSTop

41、ic(tid,TSID,TUID,TReplyCount,TEmotion,TTopic,TContents ,TTime,TClickCount,TLastClickT)values(2014 ,02,1004,0,.,我是打醬油的,就是這樣。 。 。 。,2011-1-21,1,2011-6-11)3.2.43.2.4-將已有的回帖信息加入 BBSreply 表中-replyinsertinto BBSReply(RID,RTID,RSID,RUID,REmotion,RTopic,RContents,RTime,RClickCount)values(9001 ,2001,01,1004,

42、。 。 。 。,這樣的,如此如此,這般這般,2011-6-24,1). . . . 14 / 25insertinto BBSReply(RID,RTID,RSID,RUID,REmotion,RTopic,RContents,RTime,RClickCount)values(9002 ,2011,02,1002,。 。 。 。,這樣的,如此如此,這般這般,2011-6-29,1)insertinto BBSReply(RID,RTID,RSID,RUID,REmotion,RTopic,RContents,RTime,RClickCount)values(9003 ,2003,01,1005

43、,。 。 。 。,這樣的,如此如此,這般這般,2011-6-27,1)insertinto BBSReply(RID,RTID,RSID,RUID,REmotion,RTopic,RContents,RTime,RClickCount)values(9004 ,2005,01,1005,。 。 。 。,這樣的,如此如此,這般這般,2011-6-24,1)4.4.結(jié)果數(shù)據(jù)處理結(jié)果數(shù)據(jù)處理4.14.1 單表查詢單表查詢4.1.14.1.1 表表 BBSUSERBBSUSER 中查詢演示中查詢演示: :BBSUSERBBSUSER圖-1 表 BBSUSERBBSUSER 中容4.1.24.1.2 表

44、表 BBSSECTIONBBSSECTION 中查詢演示中查詢演示: :圖-2 表 BBSSECTIONBBSSECTION 中容4.1.34.1.3 表表 BBSTOPIC 中查詢演示中查詢演示: :圖-3 表 BBSTOPIC 中容. . . . 15 / 254.1.44.1.4 表表 BBSTOPIC 中查詢演示中查詢演示: :圖-4 表 BBSTOPIC 中容4.1.54.1.5 元老查詢演示元老查詢演示: :圖-5 元老查詢SQLSQL 語句語句-查詢元老查詢元老selectselect unameuname asas ,Uemail,Uemail asas 電子電子,UregDa

45、te,UregDate asas 注冊日期注冊日期fromfrom bbsUsersbbsUsers wherewhere -datediff(yyyy,uregdate,getdate()2-datediff(yyyy,uregdate,getdate()2 dateadd(yyyy,2,uregdate)getdate()dateadd(yyyy,2,uregdate)2-datediff(yyyy,uregdate,getdate()2 dateadd(yyyy,2,uregdate)getdate()dateadd(yyyy,2,uregdate)getdate()orderorder

46、 byby UPointUPoint descdesc4.184.18 查詢所有在線用戶和禁言用戶查詢所有在線用戶和禁言用戶圖 4-8 在線與禁言用戶SQLSQL 語句語句-為了方便查詢,修改數(shù)據(jù)為了方便查詢,修改數(shù)據(jù)updateupdate bbsUsersbbsUsers setset UStateUState =3=3 wherewhere uid=1004uid=1004-查詢所有在線用戶和禁言用戶查詢所有在線用戶和禁言用戶select*select*fromfrom bbsUsersbbsUserswherewhere UStateUState = = 1 1 oror UState

47、UState = = 3 34.94.9 按回帖時間的降序顯示所有回帖標(biāo)題與回帖時間按回帖時間的降序顯示所有回帖標(biāo)題與回帖時間圖 4-9 按回帖時間的降序顯示所有回帖標(biāo)題與回帖時間SQLSQL 語句語句selectselect RTopicRTopic asas 回帖標(biāo)題回帖標(biāo)題,RTime,RTime asas 回帖時間回帖時間fromfrom bbsreplybbsreplyorderorder byby RTimeRTime descdesc4.10 列出 BBSTopic 表中點擊次數(shù)最高的前 5 名帖子圖 4-10 列出 BBSTopic 表中點擊次數(shù)最高的前 5 名帖子SQLSQL

48、 語句語句selectselect toptop 5 5 TTopicTTopic asas 主題標(biāo)題主題標(biāo)題,TClickCount,TClickCount asas 主貼點擊次數(shù)主貼點擊次數(shù)fromfrom bbstopicbbstopicorderorder byby TClickCountTClickCount descdesc4.114.11 近一周發(fā)帖最多的兩名近一周發(fā)帖最多的兩名圖 4-11 近一周發(fā)帖最多的兩名SQLSQL 語句語句-因為數(shù)據(jù)原因無法顯示,先進(jìn)行數(shù)據(jù)修改因為數(shù)據(jù)原因無法顯示,先進(jìn)行數(shù)據(jù)修改updateupdate bbstopicbbstopic setset

49、ttimettime = = 2011-6-272011-6-27 wherewhere tidtid = = 20022002updateupdate bbstopicbbstopic setset ttimettime = = 2011-6-262011-6-26 wherewhere tidtid = = 20032003updateupdate bbstopicbbstopic setset ttimettime = = 2011-6-282011-6-28 wherewhere tidtid = = 20112011updateupdate bbstopicbbstopic sets

50、et TLastClickTTLastClickT =2011-6-30=2011-6-30 wherewhere tidtid = = 20122012updateupdate bbstopicbbstopic setset ttimettime = = 2011-6-242011-6-24 wherewhere tidtid = = 20122012. . . . 17 / 25-近一周用戶發(fā)帖排名近一周用戶發(fā)帖排名-根據(jù)系統(tǒng)日期向前推根據(jù)系統(tǒng)日期向前推 7 7 天天, ,之的發(fā)帖數(shù)排名前之的發(fā)帖數(shù)排名前 2 2 名名-顯示中文列名顯示中文列名selectselect toptop 2 2

51、 tuidtuid asas 用戶用戶 IDID ,count(*),count(*) asas 發(fā)帖數(shù)發(fā)帖數(shù)fromfrom bbstopicbbstopicwherewhere datediff(dd,ttime,getdate()=7datediff(dd,ttime,getdate()=7groupgroup byby tuidtuid4.124.12 查詢用戶所發(fā)帖子的最高和最低回帖數(shù)查詢用戶所發(fā)帖子的最高和最低回帖數(shù) 圖 4-12 查詢用戶所發(fā)帖子的最高和最低回帖數(shù)SQLSQL 語句語句selectselect tuidtuid asas 用戶用戶 ID,max(TReplyCou

52、nt)ID,max(TReplyCount) 最多回帖數(shù)最多回帖數(shù),min(TReplyCount),min(TReplyCount) asas 最低回帖數(shù)最低回帖數(shù)fromfrom bbstopicbbstopicgroupgroup byby tuidtuid4.134.13 提升積分與等級評價提升積分與等級評價圖 4-13 提升積分與等級評價SQLSQL 語句語句beginbegin-T-SQL-T-SQL 編程編程declaredeclare minPointminPoint intint -定義變量,表示元老最低積分定義變量,表示元老最低積分-查詢所有元老用戶的最低積分查詢所有元老用

53、戶的最低積分, ,并賦值給并賦值給 minPointminPointselectselect minPoint=min(upoint)minPoint=min(upoint) fromfrom bbsUsersbbsUsers wherewhere dateadd(yyyy,2,uregdate)getdate()dateadd(yyyy,2,uregdate)getdate()-提分操作提分操作while(minPoint100)while(minPoint100)beginbegin updateupdate bbsUsersbbsUsers setset Upoint=Upoint+2U

54、point=Upoint+2 wherewhere dateadd(yyyy,2,uregdate)getdate()dateadd(yyyy,2,uregdate)getdate() andand Upoint198Upoint198 selectselect minPoint=min(Upoint)minPoint=min(Upoint) fromfrom bbsUSersbbsUSers wherewhere dateadd(yyyy,2,uregdate)getdate()dateadd(yyyy,2,uregdate)1000upoint1000 thenthen AAwhenwhe

55、n upoint500upoint500 thenthen BBwhenwhen upoint200upoint200 thenthen CCwhenwhen upoint100upoint100 thenthen DDelseelse EE endend fromfrom bbsUsersbbsUsersendendgogo4.144.14 創(chuàng)建存儲過程創(chuàng)建存儲過程. . . . 18 / 25圖 4-14 創(chuàng)建存儲過程SQLSQL 語句語句-定義游標(biāo)定義游標(biāo)declaredeclare cur_bbscur_bbs cursorcursor forfor selectselect uid,

56、uname,upointuid,uname,upoint fromfrom bbsUSersbbsUSers-定義局部變量定義局部變量declaredeclare uiduid int,unameint,uname char(20),upointchar(20),upoint intintopenopen cur_bbscur_bbs -打開游標(biāo)打開游標(biāo)fetchfetch cur_bbscur_bbs intointo uid,uname,upointuid,uname,upoint -第一次提取游標(biāo)第一次提取游標(biāo)while(fetch_status=0)while(fetch_status

57、=0) -判斷上一次判斷上一次 fetchfetch 操作是否提取到數(shù)據(jù)操作是否提取到數(shù)據(jù)beginbegin printprint convert(varchar(10),uid)+*+uname+*+convert(varchar(10),upoint)convert(varchar(10),uid)+*+uname+*+convert(varchar(10),upoint) fetchfetch nextnext fromfrom cur_bbscur_bbs intointo uid,uname,upointuid,uname,upoint -再次提取游標(biāo)中的下一條記錄再次提取游標(biāo)中的

58、下一條記錄endendcloseclose cur_bbscur_bbs -關(guān)閉游標(biāo)關(guān)閉游標(biāo)deallocatedeallocate cur_bbscur_bbs -刪除游標(biāo)刪除游標(biāo) , ,便于下次再次創(chuàng)建便于下次再次創(chuàng)建gogoselectselect * * fromfrom bbsSectionbbsSection-創(chuàng)建存儲過程創(chuàng)建存儲過程-存在檢測存在檢測ifif exists(selectexists(select * * fromfrom sysobjectssysobjects wherewhere name=proc_bbsname=proc_bbs andand type=P

59、)type=P) dropdrop procedureprocedure proc_bbsproc_bbsgogo-創(chuàng)建創(chuàng)建createcreate procedureprocedure proc_bbsproc_bbs -定義過程使用的參數(shù)定義過程使用的參數(shù) masterIDmasterID intint -輸入型參數(shù)輸入型參數(shù). . . . 19 / 25asasbeginbegin declaredeclare bbs_curbbs_cur cursorcursor forfor selectselect t1.snamet1.sname 版塊名版塊名,t2.uname,t2.uname 版主名版主名,t2.upoint,t2.upoint 版版主積分主積分 fromfrom bbsSectionbbsSection t1,bbsUserst1,bbsUsers t2t2 wherewhere t1.smasterID=t2.uidt1.smasterID=t2.uid andand t1.sMasterID=masterIDt1.sMasterID=masterID -參數(shù)參數(shù) declaredeclare snamesname varchar(10),unamevarchar(10),uname varchar(10),upointvarchar(10

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論