|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
只要你想学,就没什么优缺点,上面那位大哥已经把网上的评论说了,但我认为想学哪个都一样,不然它就不可能在当今时代数字艺术方面存活到今天存储历程|数据|数据布局/****************************************************************************/
/**/
/*FileName:bbs.sql*/
/**/
/*Description:bbs数据布局*/
/**/
/*Table:*/
/**/
/*Procedure:*/
/**/
/*Author:bigeaglehttp://bigeagle.yeah.net*/
/**/
/*Date:2001/1/29*/
/**/
/*History:*/
/**/
/****************************************************************************/
/*数据布局*/
/*bbs用户表*/
ifexists(select*fromsysobjectswhereid=object_id(BBSUser))
droptableBBSUser
go
createtableBBSUser
(
idintidentityprimarykey,
UserNamevarchar(20)defaultnotnull,
Passwordvarchar(10)defaultnotnull,
Emailvarchar(100)defaultnotnull,
Homepagevarchar(150)defaultnotnull,
Signaturevarchar(255)defaultnotnull,
SignDatedatetimedefaultgetdate()notnull,
Pointintdefault0notnull
)
go
createindexix_bbsuseronbbsuser(id,username,password)
/*bbs心情表*/
ifexists(select*fromsysobjectswhereid=object_id(Face))
droptableFace
go
createtableFace
(
idtinyintidentityprimarykey,
Facevarchar(30)defaultnotnull
)
go
/*bbs表*/
ifexists(select*fromsysobjectswhereid=object_id(BBS))
droptableBBS
go
createtableBBS
(
idintidentityprimarykey,
RootIDintdefault0notnull,--根ID
FatherIDintdefault0notnull,--父ID
Layertinyintdefault0notnull,--层
OrderNumfloat(53)default0notnull,--排序基数
UserIDintdefault0notnull,--讲话人ID
ForumIDtinyintdefault1notnull,--版面ID
Subjectvarchar(255)defaultnotnull,--主题
Contenttextdefaultnotnull,--内容
FaceIDtinyintdefault1notnull,--心情
Hitsintdefault0notnull,--点击数
IPvarchar(20)defaultnotnull,--发贴IP
Timedatetimedefaultgetdate()notnull,--宣布工夫
Postedbitdefault0notnull--是不是精髓贴子
)
go
createindexix_bbsonbbs(id,rootid,layer,fatherid,subject,posted)withDROP_EXISTING
createindexix_bbs1onbbs(fatherid,forumid)withDROP_EXISTING
createindexix_bbs2onbbs(forumid,rootid,ordernum)withdrop_existing
/*精髓区*/
ifexists(select*fromsysobjectswhereid=object_id(PostedTopic))
droptablePostedTopic
go
createtablePostedTopic
(
idintidentityprimarykey,
UserIDintdefault0notnull,--讲话人ID
ForumIDtinyintdefault1notnull,--版面ID
Subjectvarchar(255)defaultnotnull,--主题
Contenttextdefaultnotnull,--内容
FaceIDtinyintdefault1notnull,--心情
Hitsintdefault0notnull,--点击数
IPvarchar(20)defaultnotnull,--发贴IP
Timedatetimedefaultgetdate()notnull--宣布工夫
)
go
/*forum版面表*/
ifexists(select*fromsysobjectswhereid=object_id(forum))
droptableforum
go
createtableForum
(
IDtinyintidentityprimarykey,
RootIDtinyintdefault0notnull,--根ID
FatherIDtinyintdefault0notnull,--父ID
Layertinyintdefault0notnull,--层
Titlevarchar(50)defaultnotnull,--版面称号
Descriptionvarchar(255)defaultnotnull,--版面形貌
MasterIDintdefault1notnull,--版主ID
TopicCountintdefault0notnull,--贴子总数
Timedatetimedefaultgetdate()notnull,--创立工夫
IsOpenbitdefault0notnull--是不是开放
)
go
insertintoforum(rootid,fatherid,layer,title,description,masterid)values(1,0,0,"聊天说地","在不背犯国度功令的情形下,你能够宣布你本人的行动。",1)
insertintoforum(rootid,fatherid,layer,title,description,masterid)values(2,0,0,"体育","在不背犯国度功令的情形下,你能够对体育宣布你本人的批评。",1)
insertintoforum(rootid,fatherid,layer,title,description,masterid)values(1,1,1,"笑话站","笑话,让你在事情间隙放松一下。",1)
insertintoforum(rootid,fatherid,layer,title,description,masterid)values(2,2,1,"体育沙龙","体育总和批评。",1)
insertintoforum(rootid,fatherid,layer,title,description,masterid)values(2,2,1,"足球","足球批评。",1)
insertintoforum(rootid,fatherid,layer,title,description,masterid)values(2,2,1,"海牛俱乐部","海牛球迷的会商场地。",1)
select*fromforum
/*论坛公告表*/
ifexists(select*fromsysobjectswhereid=object_id(Notify))
droptableNotify
go
createtableNotify
(
IDintidentityprimarykey,
TopicIDintdefault0notnull,
Closedbitdefault0notnull,
)
go
select*fromnotify
deletefromnotifywhereid=5
/***********以下为存储历程************************************************************/
/*************************************************************************/
/**/
/*procedure:up_GetBBSInfo*/
/**/
/*Description:获得全部论坛的相干信息*/
/**/
/*Parameters:none*/
/**/
/*Usetable:forum,bbs,bbsuser*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/3*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetBBSInfo))
dropprocup_GetBBSInfo
go
createprocup_GetBBSInfo
as
declare@ForumCountint
declare@TopicCountint
declare@UserCountint
setnocounton
select@ForumCount=count(*)fromForumwherelayer0
select@TopicCount=count(*)fromBBS
select@UserCount=count(*)fromBBSUser
/*获得论坛自己信息*/
selectForumCount=@ForumCount,TopicCount=@TopicCount,UserCount=@UserCount
go
up_getbbsinfo
/*************************************************************************/
/**/
/*procedure:up_GetForumInfo*/
/**/
/*Description:获得指定版面的相干信息*/
/**/
/*Parameters:@a_intForumID*/
/**/
/*Usetable:forum,bbs,bbsuser*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/3*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetForumInfo))
dropprocup_GetForumInfo
go
createprocup_GetForumInfo@a_intForumIDint
as
declare@intTopicCountint
declare@intRootTopicCountint
setnocounton
ifnotexists(select*fromForumwhereid=@a_intForumID)return0
select@intTopicCount=count(*)frombbswhereforumid=@a_intForumID
select@intRootTopicCount=count(*)frombbswhereforumID=@a_intForumIDandfatherid=0
select*,TopicCount=@intTopicCount,RootTopicCount=@intRootTopicCount
fromForumwhereid=@a_intForumID
setnocountoff
go
selectid,rootid,title,fatheridfromforum
/*************************************************************************/
/**/
/*procedure:up_GetPostedForumInfo*/
/**/
/*Description:获得指定版面精髓区的相干信息*/
/**/
/*Parameters:@a_intForumID*/
/**/
/*Usetable:forum,bbs,bbsuser*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/4/17*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetPostedForumInfo))
dropprocup_GetPostedForumInfo
go
createprocup_GetPostedForumInfo@a_intForumIDint
as
declare@intTopicCountint
declare@intRootTopicCountint
setnocounton
ifnotexists(select*fromForumwhereid=@a_intForumID)return0
select@intTopicCount=count(*)frombbswhereforumid=@a_intForumIDandposted=1
select*,TopicCount=@intTopicCount,RootTopicCount=@intTopicCount
fromForumwhereid=@a_intForumID
setnocountoff
go
/*************************************************************************/
/**/
/*procedure:up_GetForumList*/
/**/
/*Description:获得版面列表*/
/**/
/*Parameters:None*/
/**/
/*Usetable:forum,bbsuser*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/10*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetForumList))
dropprocup_GetForumList
go
createprocup_GetForumList
as
selecta.id,a.rootid,a.fatherid,a.layer,a.title,a.topiccount,a.description,
UserID=b.id,b.UserName,b.Email,b.Homepage,b.Signature
fromforumasajoinBBSUserasbona.Masterid=b.IDorderbyrootid,layer
go
selectid,title,rootidfromforum
up_getforumlist
/*************************************************************************/
/**/
/*procedure:up_InsertForum*/
/**/
/*Description:新建版面*/
/**/
/*Parameters:@a_strName:版面称号*/
/*@a_strDescription:版面形貌*/
/*@a_intFatherID:分类ID,假如是0申明是年夜分类*/
/**/
/*Usetable:forum*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/4/23*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_InsertForum))
dropprocup_InsertForum
go
createprocup_InsertForum@a_strNamevarchar(50),@a_strDescriptionvarchar(255),@a_intFatherIDtinyint
as
/*界说部分变量*/
declare@intLayertinyint
declare@intRootIDtinyint
/*假如是版面而且没有指定分类,则前往-1*/
if(@a_intFatherID0andnotexists(select*fromforumwhereid=@a_intFatherID))
return(-1)
/*依据@a_intFatherID盘算layer,rootid*/
if(@a_intFatherID=0)
begin
select@intLayer=0
select@intRootID=0
end
else
begin
select@intLayer=1
select@intRootID=@a_intFatherID
end
InsertintoForum(rootid,layer,fatherid,title,description)
values(@intRootID,@intLayer,@a_intFatherID,@a_strName,@a_strDescription)
if(@a_intFatherID=0)
begin
select@intRootID=@@identity
updateForumsetrootid=@intRootIDwhereid=@intRootID
end
go
/*************************************************************************/
/**/
/*procedure:up_DeleteForum*/
/**/
/*Description:删除版面*/
/**/
/*Parameters:@a_intForumID:版面id*/
/**/
/*Usetable:forum*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/4/23*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_DeleteForum))
dropprocup_DeleteForum
go
createprocup_DeleteForum@a_intForumIDtinyint
as
deletefromForumwhereid=@a_intForumID
deletefromForumwhereRootID=@a_intForumID
go
selectid,title,rootid,fatheridfromforum
/*************************************************************************/
/**/
/*procedure:up_PostTopic*/
/**/
/*Description:发贴子*/
/**/
/*Parameters:@a_intForumID:版面id*/
/*@a_intFatherID:父贴ID,假如是新主题为0*/
/*@a_strSubject:题目*/
/*@a_strContent:内容*/
/*@a_intUserID:发贴人ID*/
/*@a_intFaceID:心情ID*/
/*@a_strIP:发贴人IP*/
/**/
/*Usetable:bbs,forum,bbsuser*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/13*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_PostTopic))
dropprocup_PostTopic
go
createprocup_PostTopic
@a_intForumIDint,
@a_intFatherIDint,
@a_strSubjectvarchar(255),
@a_strContenttext,
@a_intUserIDint,
@a_intFaceIDint,
@a_strIPvarchar(255)
as
/*界说部分变量*/
declare@intRootIDint--根id
declare@dblOrderNumfloat(53)--排序基数
declare@intLayerint--层
declare@dblNextOrderNumfloat(53)--下一回贴的ordernum
/*判别有无这个版面*/
ifnotexists(select*fromforumwhereid=@a_intForumID)
return(-1)
/*判别新贴子仍是回应贴子*/
if(@a_intFatherID=0)--根贴
begin
select@intRootID=isnull(max(id),0)+1frombbs
select@dblOrderNum=9e+24
select@intLayer=1
end
else--回贴
begin
select@intRootID=rootid,@intLayer=layer+1,@dblOrderNum=ordernum
frombbswhereid=@a_intFatherID
/*假如没找到父贴则前往毛病*/
if(@@rowcount=0)return-1
/*盘算ordernum*/
select@dblNextOrderNum=isnull(max(ordernum),0)
frombbswhereordernum<@dblOrderNumandrootid=@intRootID
select@dblOrderNum=(@dblOrderNum+@dblNextOrderNum)/2
end
/*因为对两个表操纵,用事件*/
Begintransaction
/*拔出贴子*/
insertintobbs(RootID,FatherID,Layer,OrderNum,UserID,ForumID,
Subject,Content,FaceID,IP)
values(@intRootID,@a_intFatherID,@intLayer,@dblOrderNum,
@a_intUserID,@a_intForumID,
@a_strSubject,@a_strContent,@a_intFaceID,@a_strIP)
/*判别是不是乐成*/
if(@@error!=0)gotoOnError
/*更新版面贴子数*/
updateforumsettopiccount=topiccount+1whereid=@a_intForumID
if(@@error!=0)gotoOnError
/*更新用户分数*/
updateBBSUsersetpoint=point+1whereid=@a_intUserID
if(@@error!=0)gotoOnError
/*实行*/
committransaction
return(0)
/*毛病处置*/
OnError:
rollbacktransaction
return(-1)
go
selectidfrombbswherefatherid=0orderbyrootiddesc,ordernumdesc
up_posttopic1,12,哈哈哈,见笑了,hello,world,1,1,203.93.95.10
/*************************************************************************/
/**/
/*procedure:up_GetTopicList*/
/**/
/*Description:贴子列表*/
/**/
/*Parameters:@a_intForumID:版面id*/
/*@a_intPageNo:页号*/
/*@a_intPageSize:每页显现数,以根贴为准*/
/**/
/*Usetable:bbs,forum*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/14*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetTopicList))
dropprocup_GetTopicList
go
createprocup_GetTopicList
@a_intForumIDint,
@a_intPageNoint,
@a_intPageSizeint
as
/*界说部分变量*/
declare@intBeginIDint
declare@intEndIDint
declare@intRootRecordCountint
declare@intPageCountint
declare@intRowCountint
/*封闭计数*/
setnocounton
/*检测是不是有这个版面*/
ifnotexists(select*fromforumwhereid=@a_intForumID)
return(-1)
/*求统共根贴数*/
select@intRootRecordCount=count(*)frombbswherefatherid=0andforumid=@a_intForumID
if(@intRootRecordCount=0)--假如没有贴子,则前往零
return0
/*判别页数是不是准确*/
if(@a_intPageNo-1)*@a_intPageSize>@intRootRecordCount
return(-1)
/*求入手下手rootID*/
set@intRowCount=(@a_intPageNo-1)*@a_intPageSize+1
/*限定条数*/
setrowcount@intRowCount
select@intBeginID=rootidfrombbswherefatherid=0andforumid=@a_intForumID
orderbyiddesc
/*停止rootID*/
set@intRowCount=@a_intPageNo*@a_intPageSize
/*限定条数*/
setrowcount@intRowCount
select@intEndID=rootidfrombbswherefatherid=0andforumid=@a_intForumID
orderbyiddesc
/*恢复体系变量*/
setrowcount0
setnocountoff
selecta.id,a.layer,a.forumid,a.subject,a.faceid,a.hits,a.time,a.UserID,a.fatherid,a.rootid,
Bytes=datalength(a.content),b.UserName,b.Email,b.HomePage,b.Signature,b.Point
frombbsasajoinBBSUserasbona.UserID=b.ID
whereForumid=@a_intForumIDanda.rootidbetween@intEndIDand@intBeginID
orderbya.rootiddesc,a.ordernumdesc
return(@@rowcount)
--select@@rowcount
go
up_getTopiclist3,1,20
select*frombbswherefatherid=0orderbyiddesc
select*frombbsuser
/*************************************************************************/
/**/
/*procedure:up_GetPostedTopicList*/
/**/
/*Description:精髓区贴子列表*/
/**/
/*Parameters:@a_intForumID:版面id*/
/*@a_intPageNo:页号*/
/*@a_intPageSize:每页显现数,以根贴为准*/
/**/
/*Usetable:bbs,forum*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/14*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetPostedTopicList))
dropprocup_GetPostedTopicList
go
createprocup_GetPostedTopicList
@a_intForumIDint,
@a_intPageNoint,
@a_intPageSizeint
as
/*界说部分变量*/
declare@intBeginIDint
declare@intEndIDint
declare@intRootRecordCountint
declare@intPageCountint
declare@intRowCountint
/*封闭计数*/
setnocounton
/*检测是不是有这个版面*/
ifnotexists(select*fromforumwhereid=@a_intForumID)
return(-1)
/*求统共根贴数*/
select@intRootRecordCount=count(*)frombbswhereposted=1andforumid=@a_intForumID
if(@intRootRecordCount=0)--假如没有贴子,则前往零
return0
/*判别页数是不是准确*/
if(@a_intPageNo-1)*@a_intPageSize>@intRootRecordCount
return(-1)
/*求入手下手rootID*/
set@intRowCount=(@a_intPageNo-1)*@a_intPageSize+1
/*限定条数*/
setrowcount@intRowCount
select@intBeginID=rootidfrombbswhereposted=1andforumid=@a_intForumID
orderbyiddesc
/*停止rootID*/
set@intRowCount=@a_intPageNo*@a_intPageSize
/*限定条数*/
setrowcount@intRowCount
select@intEndID=rootidfrombbswhereposted=1andforumid=@a_intForumID
orderbyiddesc
/*恢复体系变量*/
setrowcount0
setnocountoff
selecta.id,a.layer,a.forumid,a.subject,a.faceid,a.hits,a.time,a.UserID,a.fatherid,a.rootid,
Bytes=datalength(a.content),b.UserName,b.Email,b.HomePage,b.Signature,b.Point
frombbsasajoinBBSUserasbona.UserID=b.ID
whereposted=1andForumid=@a_intForumIDanda.rootidbetween@intEndIDand@intBeginID
orderbya.rootiddesc,a.ordernumdesc
return(@@rowcount)
--select@@rowcount
go
selectid,rootid,fatherid,forumid,postedfrombbs
up_getpostedtopiclist3,1,20
/*************************************************************************/
/**/
/*procedure:up_GetTopic*/
/**/
/*Description:取贴子*/
/**/
/*Parameters:@a_intTopicID:贴子id*/
/**/
/*Usetable:bbs*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/16*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetTopic))
dropprocup_GetTopic
go
createprocup_GetTopic@a_intTopicIDint
as
/*假如没有这贴子*/
ifnotexists(select*frombbswhereid=@a_intTopicID)
return(-1)
/*更新该贴的点击数*/
updatebbssethits=hits+1whereid=@a_intTopicID
selecta.*,Bytes=datalength(a.content),
b.UserName,b.Email,b.Homepage,b.point,b.Signature
frombbsasajoinBBSUserasbona.UserID=b.id
wherea.id=@a_intTopicID
go
up_getTopic11
/*************************************************************************/
/**/
/*procedure:up_DeleTopic*/
/**/
/*Description:删除贴子及子贴,更新发贴人信息*/
/**/
/*Parameters:@a_intTopicID:贴子id*/
/**/
/*Usetable:bbs*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/2/24*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_DeleTopic))
dropprocup_DeleTopic
go
createprocup_DeleTopic@a_intTopicIDint
as
/*界说部分变量*/
declare@intRootIDint
declare@intLayerint
declare@floatOrderNumfloat(53)
declare@floatNextOrderNumfloat(53)
declare@intCountsint
declare@intForumIDint
/*作废计数*/
setnocounton
/*起首查找这个贴子的rootid和ordernum,没有则前往*/
select@intRootID=RootID,
@floatOrderNum=OrderNum,
@intLayer=layer,
@intForumID=forumid
frombbswhereid=@a_intTopicID
if@@rowcount=0
return(-1)
/*取下一个同层贴子的ordernum*/
select@FloatNextOrderNum=isnull(max(ordernum),0)
frombbs
whereRootID=@intRootID
andlayer=@intLayerandordernum<@floatOrderNum
/*多表操纵,用事件*/
begintransaction
/*起首删贴*/
deletefrombbs
whererootid=@intRootIDandordernum>@floatNextOrderNum
andordernum<=@floatOrderNum
select@intCounts=@@rowcount
if(@@error!=0)
gotoError
/*论坛贴子数削减*/
updateforumsettopiccount=topiccount-@intCountswhereid=@intForumID
if(@@error!=0)
gotoError
/*完成事件,前往*/
committransaction
setnocountoff
return(0)
Error:
rollbacktransaction
setnocountoff
return(-1)
go
selectforumidfrombbs
updatebbssetforumid=4
/*************************************************************************/
/**/
/*procedure:up_GetUserInfo*/
/**/
/*Description:获得发贴人信息*/
/**/
/*Parameters:@a_strUserName:用户笔名*/
/**/
/*Usetable:bbsuser*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/4/16*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_GetUserInfo))
dropprocup_GetUserInfo
go
createprocup_GetUserInfo@a_strUserNamevarchar(20)
as
declare@m_intOrderint--排名
declare@m_intPointint--积分
setnocounton
/*假如没有找到该用户,则前往-1*/
select@m_intPoint=pointfrombbsuserwhereusername=@a_strUserName
if(@@rowcount=0)
return(-1)
/*求排名*/
select@m_intOrder=count(*)+1frombbsuserwherepoint>@m_intPoint
select*,order=@m_intOrderfrombbsuserwhereusername=@a_strUserName
setnocountoff
go
up_getuserinfo廖家远
/*************************************************************************/
/**/
/*procedure:up_PostedTopic*/
/**/
/*Description:将贴子转进精髓区*/
/**/
/*Parameters:@a_intTopicID贴子id*/
/**/
/*Usetable:bbs,postedtopic*/
/**/
/*Author:bigeagle@163.net*/
/**/
/*Date:2000/4/17*/
/**/
/*History:*/
/**/
/*************************************************************************/
ifexists(select*fromsysobjectswhereid=object_id(up_postedtopic))
dropprocup_postedtopic
go
createprocup_PostedTopic@a_intTopicIDint
as
/*界说部分变量*/
declare@m_intUserIDint--发贴人ID
/*查找是不是有这个贴子*/
select@m_intUserID=useridfrombbswhereid=@a_intTopicID
if(@@rowcount!=1)
return-1
/*由于对两个表操纵以是用事件*/
begintransaction
updatebbssetposted=1whereid=@a_intTopicID
if(@@error0)
gotoError
updatebbsusersetpoint=point+3whereid=@m_intUserID
if(@@error0)
gotoError
Committransaction
return(0)
Error:
rollbacktransaction
go
ASP脚本是采用明文(plaintext)方式来编写的。 |
|