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

下載本文檔

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

文檔簡介

本文格式為Word版,下載可任意編輯——bbs論壇數(shù)據(jù)庫設(shè)計

簡單的BBS數(shù)據(jù)庫設(shè)計!

網(wǎng)易新聞

微博

郵箱

閃電郵

相冊

有道

手機郵

印像派

夢幻人生

更多博客博客首頁

博客話題

熱點專題

博客油菜地

找朋友

博客圈子

博客風(fēng)格

手機博客

郵件寫博

博客復(fù)制探尋搜博文搜博客隨便看看注冊登錄愛的天與地Loveofheavenandearth

導(dǎo)航

首頁日志相冊音樂珍藏博友關(guān)于我日志愛的天與熱心、熱心、還是熱心.我的生活充滿熱心,充滿絢爛,微笑面對每一天.

加博友關(guān)注他

最新日志

Sql腳本使用技巧(selectint房產(chǎn)管理系統(tǒng)數(shù)據(jù)庫設(shè)計.NET平臺C#+WinForms編程項.NET平臺實現(xiàn)C#編程http://.77平臺實現(xiàn)C#編程http://.77平臺實現(xiàn)C#編程WinForms博主推薦

相關(guān)日志

隨機閱讀

營養(yǎng)缺乏身體會發(fā)出信號雙向看人看自己生氣,對身體有內(nèi)在的驚人傷害寫博客是一種最好的修煉造心老年斑只是不好看而已嗎?首頁推薦

90后少女彪悍的可以當(dāng)我老師爆笑《木蘭做月餅》肖傳國該判幾年?警方破獲方舟子被打案10%住房空置率很正常李冰冰色誘華仔就能色誘觀眾?更多

SQLServer數(shù)據(jù)庫應(yīng)用開發(fā)(1)SQLServer數(shù)據(jù)庫事物處理過程

一個不完整的BBS論壇數(shù)據(jù)庫設(shè)計程序人生2023-08-2021:35:19閱讀539評論2字號:大中小訂閱

usemaster

新建數(shù)據(jù)bbsDB的庫

go

--判斷數(shù)據(jù)庫是否存在使用exists關(guān)鍵字,在用sysdatabases關(guān)鍵字查詢--

ifexists(select*fromsysdatabaseswherename='bbsDB')

--假使數(shù)據(jù)庫存在就刪除此數(shù)據(jù)庫用drop(刪除)database(數(shù)據(jù)庫對象)bbsDB(數(shù)據(jù)庫名)--

dropdatabasebbsDB

--刪除后在添加一個數(shù)據(jù)庫create(添加)database(數(shù)據(jù)庫對象)bbsDB(數(shù)據(jù)庫名)on--

createdatabasebbsDB

on

(

name='bbsDB_MDF',--數(shù)據(jù)庫主文件名--

filename='F:\SQL\第四階段\bbsDB_MDF.mdf',--數(shù)據(jù)庫存儲的路徑--

size=10mb,--數(shù)據(jù)庫初使大小--

filegrowth=10%--增長變化--

)

--設(shè)置日志文件--

logon

(

name='bbsDB_LDF',--日志文件名--

filename='F:\SQL\第四階段\bbsDB_LDF.ldf',--日志文件存儲路徑--

size=1mb,--日志文件初使大小--

maxsize=20mb,--日志文件最大的可儲存--

filegrowth=10%--增長變化--

)

go

以上信息為新建的數(shù)據(jù)庫

usebbsDB

go

新建bbsUsers表(用戶表)

--判斷bbsDB庫是否有表bbsUser的存在exists關(guān)鍵字+sysobjects判

斷當(dāng)前數(shù)據(jù)庫表--

ifexists(select*fromsysobjectswherename='bbsUsers')

--假使表存在就刪除此表--

droptablebbsUser

--新建bbsUser表--

createtablebbsUsers

簡單的BBS數(shù)據(jù)庫設(shè)計!

(

UIDintidentity(1,1)notnull,--用戶編號,自動增長列,不允許空--

Unamevarchar(50)notnull,--用戶名,不允許空--

Upasswordvarchar(50)notnull,--密碼,不允許空--

Uemailvarchar(50),--郵箱--

Usexchar(2)notnull,--性別,不允許空--

Uclassint,--用戶等級--

Uremarkvarchar(50),--備注信息--

UregDatedatetimenotnull,--注冊日期,不允許空--

Ustateint,--狀態(tài),是否在線等--

Upointint,--用戶的積分--

)

go

為用戶表添加各種約束

--為bbsUser表添加約束,addconstraint關(guān)鍵字PK_UID約束名,primarykey(主鍵)設(shè)置UID字段為主鍵--

altertablebbsUsers

addconstraintPK_UIDprimarykey(UID)

--為Upassword添加約束,check(Upasswordlength=6)字段長度大于等于6位,default設(shè)置默認(rèn)值為888888--

altertablebbsUsers

addconstraintCK_Upasswordcheck(len(Upassword)=6)

altertablebbsUsers

addconstraintDF_Upassworddefault('888888')forUpassword

--為Uemail字段添加約束,必需包含@號--

altertablebbsUsers

addconstraintCK_Uemailcheck(Uemaillike'%@%')

--為User字段添加約束,設(shè)置默認(rèn)值為男,并且值只能是男或女--

altertablebbsUsers

addconstraintDF_Usexdefault('男')forUsex

altertablebbsUsers

addconstraintCK_Usexcheck(Usex='男'orUsex='女')

--為Uclass字段添加約束,默認(rèn)值為1--

altertablebbsUsers

addconstraintDF_Uclassdefault(1)forUclass

--為UregDate字段添加約束,默認(rèn)值為當(dāng)前日期--

altertablebbsUsers

addconstraintDF_UregDatedefault(getDate())forUregDate

--為Ustate添加約束,默認(rèn)值為0--

altertablebbsUsers

addconstraintDF_Ustatedefault(0)forUstate

--為Upoint字段添加約束,默認(rèn)值為20--

altertablebbsUsers

addconstraintDF_Upointdefault(20)forUpoint

以上信息為以建立的bbsUser(用戶表)及各種約束

go

新建bbsSection表(版塊表)

--判斷數(shù)據(jù)庫內(nèi)是否有表bbsSection的存在--

ifexists(select*fromsysobjectswherename='bbsSection')

--假使有此表執(zhí)行刪除--

droptablebbsSection

--新建bbsSection表,及個字段--

createtablebbsSection

(

SIDintidentity(1,1)notnull,--版塊編號,自動增長列--

Snamevarchar(50)notnull,--版塊名稱,不允許空--

SmasterIDintnotnull,--版主ID--

Sprofilevarchar(50),--版面簡介--

SclickCountint,--點擊率--

StopicCountint--發(fā)貼數(shù)--

)

為表bbsSection(版塊表)添加約束-

go

--將SID字段設(shè)置為主鍵--

altertablebbsSection

addconstraintPK_SIDprimarykey(SID)

--為SmasterI

簡單的BBS數(shù)據(jù)庫設(shè)計!

D設(shè)置外鍵,他的主鍵是bbsUsers表的UID字段foreignkey(外鍵)references主鍵表(主鍵表字段)--

altertablebbsSection

addconstraintFK_SmasterIDforeignkey(SmasterID)referencesbbsUsers(UID)

--為SclickCount字段添加默認(rèn)值為0--

altertablebbsSection

addconstraintDF_SclickCountdefault(0)forSclickCount

--為字段StopicCount設(shè)置默認(rèn)值為0--

altertablebbsSection

addconstraintDF_StopicCountdefault(0)forStopicCount

以上為表bbsSection(版塊表)建立及添加相應(yīng)約束

新建bbsTopic表(主貼表)

go

--判斷數(shù)據(jù)庫中是否有bbsTopic表的存在--

ifexists(select*fromsysobjectswherename='bbsTopic')

--刪除此表--

droptablebbsTopic

--新建bbaTopic表及個字段--

createtablebbsTopic

(

TIDintidentity(1,1)notnull,--帖子編號--

TsIDintnotnull,--版塊編號--

TuIDintnotnull,--發(fā)貼人ID--

TreplyCountint,--回復(fù)數(shù)量--

Tfaceint,--發(fā)貼表情--

Ttopicvarchar(50)notnull,--標(biāo)題--

Tcontentsvarchar(50)notnull,--正文--

Ttimedatetime,--發(fā)貼時間--

TclickCountint,--點擊數(shù)--

Tstateintnotnull,--狀態(tài)--

TlastReplydatetime--最終回復(fù)時間--

)

為bbsTopic(主貼表)表個字段添加約束

go

--將TID字段設(shè)置為主鍵--

altertablebbsTopic

addconstraintPK_TIDprimarykey(TID)

--將TsID設(shè)置為外鍵,引用bbsSection表的主鍵SID字段--

altertablebbsTopic

addconstraintFK_TsIDforeignkey(TsID)referencesbbsSection(SID)

--將TuID字段設(shè)置為外鍵盤,引用bbsUsers表的主鍵UID字段--

altertablebbsTopic

addconstraintFK_TuIDforeignkey(TuID)referencesbbsUsers(UID)

--設(shè)置TreplyCount字段的默認(rèn)值為0--

altertablebbsTopic

addconstraintDF_TreplyCountdefault(0)forTreplyCount

--為Tcontents字段添加約束,他的值必需大于等于6位--

altertablebbsTopic

addconstraintCK_Tcontentscheck(len(Tcontents)=6)

--為Ttime字段添加默認(rèn)值,為當(dāng)前日期--

altertablebbsTopic

addconstraintDF_Ttimedefault(getDate())forTtime

--設(shè)置TclickCount字段默認(rèn)值為0--

altertablebbsTopic

addconstraintDF_TclickCountdefault(0)forTclickCount

--設(shè)置Tstate字段默認(rèn)值為1--

altertablebbsTopic

addconstraintDF_Tstatedefault(1)forTstate

--為TlastReply字段添加約束,最終回復(fù)時間必需要晚于發(fā)貼時間--

altertablebbsTopic

addconstraintCK_TlastReplycheck(TlastReplyTtime)

以上為bbsT

opic(主貼表)表建立及建立個字段

新建表bbsReply(回帖表)及個字段

簡單的BBS數(shù)據(jù)庫設(shè)計!

心酸果凍用戶發(fā)貼回帖顯示級別

--聲明變量用于存儲用戶ID--

declare@uNameIDint

--聲明變量用于存儲用戶發(fā)貼數(shù)量--

declare@countint

--聲明變量用于存儲用戶回帖數(shù)量--

declare@count1int

--將心酸果凍用戶的ID號存到變量@uNameID中--

select@uNameID=UIDfrombbsUserswhereUname='心酸果凍'

--用count統(tǒng)計函數(shù)將用戶的發(fā)貼數(shù)量存到變量@count中--

select@count=count(*)frombbsTopicwhereTuID=@uNameID

--輸出--

print'心酸果凍發(fā)貼數(shù)量為:'+convert(varchar(10),@count)

print''

print'具體內(nèi)容如下:'

--顯示信息,判斷用戶發(fā)貼數(shù)量大于0時顯示帖子的信息--

if(@count0)

selectTtimeas發(fā)貼時間,TclickCountas點擊率,Ttopicas主題,Tcontentsas內(nèi)容frombbsTopicwhereTuID=@uNameID

--用count統(tǒng)計函數(shù)將用戶的回貼數(shù)量存到變量@count1中--

select@count1=count(*)frombbsReplywhereRuID=@uNameID

--輸出--

print'心酸果凍的回帖數(shù)量為:'+convert(varchar(10),@count1)

--顯示信息,用戶回帖數(shù)量大于0時顯示帖子信息--

if(@count10)

selectRtimeas回帖時間,RclickCountas點擊數(shù)量,Rcontentsas回帖內(nèi)容frombbsReplywhereRuID=@uNameID

--判斷用戶的等級--

if((@count+@count1)10)

print'心酸果凍貼數(shù)總計為:'+convert(varchar(10),@count+@count1)+'功臣級別為:新手上路'

if(((@count+@count1)=10)and((@count+@count1)20))

print'心酸果凍貼數(shù)總計為:'+convert(varchar(10),@count+@count1)+'功臣級別為:俠客'

if(((@count+@count1)=20)and((@count+@count1)30))

print'心酸果凍貼數(shù)總計為:'+convert(varchar(10),@count+@count1)+'功臣級別為:騎士'

if(((@count+@count1)=30)and((@count+@count1)40))

print'心酸果凍貼數(shù)總計為:'+convert(varchar(10),@count+@count1)+'功臣級別為:精靈王'

if(((@count+@count1)=40)and((@count+@count1)50))

print'心酸果凍貼數(shù)總計為:'+convert(varchar(10),@count+@count1)+'功臣級別為:光明使者'

if((@count+@count1)=50)

print'心酸果凍貼數(shù)總計為:'+convert(varchar(10),@count+@count1)+'功臣級別為:法老'

回帖最多的為精華貼

--聲明整形變量用于存儲主貼編號,和編號--

declare@tididint

declare@zhuzheidint

declare@huifuint

--將主貼標(biāo)號存到@tidid變量中--

selecttop1@tidid=TIDfrombbsTopicorderbyTrep

lyCountdesc

--將用戶編號存到@zhuzheid變量中--

select@zhuzheid=TuIDfrombbsTopicwhereTID=@tidid

--輸出--

print'第一精華貼的信息如下:'

--查出回貼最多的主貼,(用戶表與主

簡單的BBS數(shù)據(jù)庫設(shè)計!

貼表兩表連查)--

selectTtimeas發(fā)貼時間,TclickCountas點擊率,Unameas,Ttopicas主題,Tcontentsas內(nèi)容frombbsTopic

innerjoinbbsUsers

onbbsUsers.UID=bbsTopic.TuID

wherebbsUsers.UID=@zhuzheidandbbsTopic.TID=@tidid

--為了美觀輸出空行--

print''

--利用@tidid(主貼編號)變量查出回復(fù)數(shù)量存到@huifu變量中--

select@huifu=TreplyCountfrombbsTopicwhereTID=@tidid

--輸出--

print'回帖數(shù)量'+convert(varchar(10),@huifu)+',如下所示:'

--查詢回帖信息--

selectRtimeas回帖時間,RclickCountas點擊率,回帖表情=case

--case多分之語句判斷回帖表情--

whenRface=1then'~(00)~豬頭'

whenRface=2then'*:0)小丑'

whenRface=3then'[:|]機器人'

whenRface=4then'{~0~0~}老人家'

whenRface=5then'(:)吹水大王'

end

,Rcontentsas回帖內(nèi)容frombbsReplywhereRtID=@tidid

/*實現(xiàn):1、論壇人氣,點擊率1000為“人氣熊旺旺〞,否則為“一般般〞

2、年度品牌版塊:主貼量最多的版塊

3、年度倒胃版塊:主貼量最少的版塊

4、年度回帖人氣最旺獎:回帖的點擊率排名前2名

5、年度最差斑竹:版塊點擊率低于500或主貼等于0*/

--1、論壇人氣,點擊率1000為“人氣熊旺旺〞,否則為“一般般〞--

print'各位大蝦注意了,本論壇即將發(fā)布年度獎項'

if(selectsum(SclickCount)frombbsSection)1000

print'論壇人氣評估:人氣熊旺旺大家辛苦了'

else

print'論壇人氣評估:一般般,大家加油了'

--2、年度品牌版塊:主貼量最多的版塊--

print'年度最正確版塊'

selectSnameas版塊名稱,StopicCountas主貼數(shù)量,Sprofileas簡介frombbsSection

whereStopicCount=(selectmax(StopicCount)frombbsSection)

--3、年度倒胃版塊:主貼量最少的版塊--

print'年度倒胃版塊'

selectSnameas版塊名稱,StopicCountas主貼數(shù)量,Sprofileas簡介frombbsSection

whereStopicCount=(selectmin(StopicCount)frombbsSection)

--4、年度回帖人氣最旺獎:回帖的點擊率排名前2名--

print'年度回帖人氣最旺的前兩位'

selectUnameas大名,Uclassas星級frombbsUserswhereuidin(

selecttop2TuIDfrombbsTopicorderbyTclickCountdesc)

--5、年度最差斑竹:版塊點擊率低于500或主貼等于0--

ifexists(select*frombbsSectionwhereStopicCount=0orSclickCount=500)

begin

print'請以下斑竹加油哦'

selectSnameas版塊名稱,StopicCountas主貼數(shù)量,SclickCountas點擊率frombbsSection

whereStopicCount=

0orSclickCount=500

end

簡單的BBS數(shù)據(jù)庫設(shè)計!

datebbsUserssetUpoint=Upoint+50whereUID=@GTid

--更新用戶相應(yīng)的信息--

updatebbsUserssetUclass=case

whenUpoint500then1

whenUpointbetween500and1000then2

whenUpointbetween1001and2000then3

whenUpointbetween2023and4000then4

whenUpointbetween4001and5000then5

else6

end

--發(fā)布主貼和跟貼--

select主貼='心酸果凍',主貼發(fā)布時間=convert(varchar(10),Ttime,111),主題=Ttopic,內(nèi)容=Tcontents

frombbsTopicwhereTID=@@identity

select回帖='可卡因',回帖時間=convert(varchar(10),Rtime,111),回帖內(nèi)容=Rcontents

frombbsReplywhereRID=@@identity

--星級從新排名--

select妮稱=Uname,星級=case

whenUclass=0then''

whenUclass=1then'★'

whenUclass=2then'★★'

whenUclass=3then'★★★'

whenUclass=4then'★★★★'

whenUclass=5then'★★★★★'

else'★★★★★★'

end

,積分=UpointfrombbsUsers

/*刪除帖子*/

--聲明變量用于存放回帖人編號及主貼ID--

declare@GTidint

declare@BZidint

declare@ZTidint

declare@BKidint

--獲得斑竹心酸果凍的編號--

select@BZid=UIDfrombbsUserswhereUname='心酸果凍'

--獲得主貼的編號--

select@ZTid=TIDfrombbsTopicwhereTtopiclike'%什么是.Net%'

--獲得所有回帖人的編號--

select@GTid=RuIDfrombbsReplywhereRtID=@ZTid

--獲得版塊編號--

select@BKid=SIDfrombbsSectionwhereSnamelike'%.Net%'

--被刪帖的斑竹心酸果凍減去積分100分--

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論