QQ程序-QQ数据库详解

2009年3月28日星期六

QQ程序-QQ数据库详解

1. admin 管理员表 username(char) 管理员名 userpass(char) 管理员密码

2. ArcReview 评论表 iRevId(int) 主键ID tRevText(text)评论的内容

iArtId(int)评论的文章 cPubNum(char)

3.Art 文章表 iArtId(int) 文章ID iBrowseCount(int)浏览次数 tArtContent(text)文章内容

cPubTime(char)发表时间 iModeId(int) 模板id vcArtName(varchar)文章标题

4.ArtModule 模板表 iModeId(int) 模板id cZoneOwner(char)谁的空间 vcModeName(varchar) 模板标题

5.collection 我的收藏 c_id(int)收藏id c_title(varchar)收藏标题 c_content(text)收藏内容

hits(点击次数)c_time(收藏时间)

6.FriendList 好友表 iFriendId(int)ID标识 cFriendNum(char)好友QQ号 iGroupId(int)好友分组

cQQNum(char) QQ号

7.GroupInf 分组表 iGroupId(int) ID标识 cGroupName(char)分组名称 GroupOwner(int)QQ

8.guest 用户资料表 id(int)标识 name(char)用户名 face(char)头像 oicq(char)QQ号码

email(char)email url(char)主页空间地址 ly(varchar)个性签名 re(varchar)个人说明

rtime(datetime)修改时间 title(char)

9.LeaveWord 小纸条 iLeaveId(int)标识id tLeaveText(text)内容 cUserId(char)用户

10.new id(int)标识 title(varchar)标题 content(text)内容 hits(int)点击次数

newtime(datetime)发表时间

11.UserInf 用户表 cUserName(char)用户昵称 cQQNum(char) QQ号码 vaEmail(varchar)email

irank(int) vcUserHeader(varchar)头像 cSex(性别) vcQuserPwd(varchar)用户密码

12. ZoneAndLeave 收到纸条 cZoneOwner(char)空间所有者 iLeaveId(int)纸条id

13. ZoneInf 空间表 cZoneOwner(char)空间所有者 vcZoneName(varchar)空间名称

vcZoneBgImg(varchar)空间背景图片 vsBgSound(varchar)空间背景音乐

tZoneDes(text)空间个性说明 iStyId(int)样式

14.ZoneStyle 空间样式 iStyId(int)标识id vcFileUrl(varchar)样式地址

cStyleName(char)样式名称



各表存在的关系

ArcReview的iArtId和Art的iArtId

Art的iModeId和ArtModule的iModeId

ArtModule的cZoneOwner和ZoneInf的cZoneOwner

FriendList的cQQNum和UserInf的cQQNum

FriendList的iGroupId和GroupInf的iGroupId

ZoneAndLeave的iLeaveId和LeaveWord的iLeaveId

ZoneAndLeave的cZoneOwner和ZoneInf的cZoneOwner

UserInf的cQQNum和ZoneInf的cZoneOwner

ZoneInf的iStyId和ZoneStyle的iStyId



视图

GetAllUser 察看所有用户昵称和QQ号码



create view GetAllUser
as
select cUserName,cQQNum from UserInf





viGetStyleList 参看QQ空间样式信息

create view viGetStyleList
as
select iStyId,cStyleName from ZoneStyle






设置存储过程



AddFriend 添加好友



CREATE proc AddFriend
(
@Owner char(8), --QQ号
@FriendNumber char(8),--好友QQ号
@GroupId int, --分组类别
@result int output --输出参数,0代表添加成功,-1,1代表失败
)
as
begin
if @GroupId=-1
begin
select @GroupId=iGroupId from GroupInf where GroupOwner=@Owner and cGroupName='我的好友'
end
if exists(select * from UserInf where cQQNum=@FriendNumber)--查询是否有该用户
begin
if exists(select * from FriendList where cQQNum=@Owner and cFriendNum=@FriendNumber)
begin
set @result=1--该条纪录已经存在
end
else
begin
insert into FriendList(cQQNum,cFriendNum,iGroupId) values(@Owner,@FriendNumber,@GroupId)
set @result=0--添加纪录成功
end
end
else
begin
set @result=-1--要添加的好友不存在
end
end
GO




AddNewArt 添加文章



create proc AddNewArt
(
@ModeId int, --模板
@ArtName varchar(20), --文章标题
@ArtContent text, --文章内容
@PubTime char(10) --发表时间
)
as
begin
insert into Art(iBrowseCount,tArtContent,cPubTime,iModeId,vcArtName) values(0,@ArtContent,@PubTime,@ModeId,@ArtName) --初始浏览次数为0
end

GO




AddNewGroup 添加新的分组



create proc AddNewGroup
(
@GroupOwner char(8), --分组所有者,QQ号
@GroupName char(10), --分组名称
@Result int output --输出参数 1成功 -1失败
)
as
begin --分组是否已经存在
if exists(select * from GroupInf where cGroupName=@GroupName and GroupOwner=@GroupOwner)
begin
set @Result=-1
end
else
begin
insert into GroupInf(GroupOwner,cGroupName) values(@GroupOwner,@GroupName) --添加分组
set @Result=1
end
end

GO


ChangeFriGroup 改变好友所属的分组



CREATE proc ChangeFriGroup
(
@FriendId int,--好友id标识
@DestiGroup int--目的分组
)
as
begin
if @DestiGroup=-1
begin
declare @tempGroupId int,@tempUserId char(8) --添加新的自定义参数 我的好友分组ID,我的QQ号
select @tempUserId=cQQNum from FriendList where iFriendId=@FriendId --我的QQ号
select @tempGroupId=iGroupId from GroupInf where GroupOwner=@tempUserId and cGroupName='我的好友' --获取我的QQ号中 我的好友的ID
update FriendList set iGroupId=@tempGroupId where iFriendId=@FriendId --修改好友表的分组
end
else
begin
update FriendList set iGroupId=@DestiGroup where iFriendId=@FriendId--改变到新的分组
end
end
GO




CreateGroup 创建新的分组



create proc CreateGroup
(
@GroupOwner char(8), --分组所有者 QQ
@GroupName char(10) --分组名称
)
as
begin
insert into GroupInf(cGroupName,GroupOwner) values(@GroupName,@GroupOwner)
end


GO


DelGroupName 删除用户分组


create proc DelGroupName

(
@GroupId int --分组的id标识
)
as
begin
declare @tempId int --获取'我的好友'的 分组标识
declare @tempUser char(8) --该分组的用户QQ
select @tempUser=GroupOwner from GroupInf where iGroupId=@GroupId --获取该用户
select @tempId=iGroupId from GroupInf where GroupOwner=@tempUser and cGroupName='我的好友'
update FriendList set iGroupId=@tempId where iGroupId=@GroupId

--将该分组下面的好友转到'我的好友'分组下面
delete GroupInf where iGroupId=@GroupId --删除该分组
end


GO





DelThisFriend 删除指定好友



create proc DelThisFriend
(
@FriendId int
)
as
begin
delete FriendList where iFriendId=@FriendId
end

GO



GetArtList 获取文章列表

create proc GetArtList

(
@Model int, --0:获取前面10条记录否则获取全部记录
@ModeId int, --模板ID
@ModeOwner char(8) --该模板所属的QQ空间
)
as
begin
if @Model=0
begin
select top 10 iArtId,vcArtName,cPubTime from Art,ArtModule where Art.iModeId=ArtModule.iModeId and ArtModule.cZoneOwner=@ModeOwner order by cPubTime desc
end
else
begin
select iArtId,vcArtName,cPubTime from Art where iModeId=@ModeId order by cPubTime desc
end
end

GO



GetFriendByGroupId 根据分组ID返回该分组的好友



CREATE proc GetFriendByGroupId
(
@GroupId int
)
as
begin
select iFriendId,cUserName from FriendList,UserInf where iGroupId=@GroupId and FriendList.cFriendNum=UserInf.cQQNum
end
GO



GetFriendListDefault 根据用户id获取所有默认分组的好友名单



CREATE proc GetFriendListDefault
(
@UserId char(8)
)
as
begin
declare @tempGroupId int
select @tempGroupId=iGroupId from GroupInf where GroupOwner=@UserId and cGroupName='我的好友'
select iFriendId,cUserName from FriendList,UserInf where FriendList.cFriendNum=UserInf.cQQNum and FriendList.cQQNum=@UserId and iGroupId=@tempGroupId
return
end
GO






GetFriendLsit 通过用户id获取好友列表


CREATE proc GetFriendLsit
(
@cQQNum char(8)
)
as
begin
select GroupInf.cGroupName,FriendList.cFriendNum,UserInf.cUserName
from GroupInf,FriendList,UserInf
where FriendList.iGroupId=GroupInf.iGroupId
and UserInf.cQQNum=FriendList.cFriendNum
and FriendList.cQQNum=@cQQNum
and GroupInf.GroupOwner=@cQQNum
end
GO



GetGroupInf 根据用户id获取该用户的分组

CREATE proc GetGroupInf
(
@UserId char(8),
@Model int
)
as
begin
if @Model=1
begin
select iGroupId,cGroupName from GroupInf where GroupOwner=@UserId
end
else
begin
select iGroupId,cGroupName from GroupInf where GroupOwner=@UserId and cGroupName!='我的好友'
end
end
GO





GetModelList 根据用户名获取所有模块列表



create proc GetModelList
(
@ZoneOwner char(8)
)
as
begin
select iModeId,vcModeName from ArtModule where cZoneOwner=@ZoneOwner
end

GO







GetUserNameByNumber 通过用户号码获取用户名称


create proc GetUserNameByNumber
(
@UserNumber char(8)
)
as
begin
select cUserName from UserInf where cQQNum=@UserNumber
end

GO



GetZoneInf



create proc GetZoneInf 根据id获取空间资料
(
@Owner char(8)
)
as
begin
select vcZoneName,vcZoneBgImg,vsBgSound,tZoneDes,iStyId from ZoneInf where cZoneOwner=@Owner
end

GO




MakeNewModel 创建新的模块



create proc MakeNewModel
(
@ModelName varchar(20), --模板名称
@ModelOwner char(8), --模板所有者-QQ空间
@Result int output --0 失败,1成功
)
as
begin
if exists(select * from ArtModule where cZoneOwner=@ModelOwner and vcModeName=@ModelName)

--是否已经存在该模板
begin
set @Result=0
end
else
begin
insert into ArtModule(cZoneOwner,vcModeName) values(@ModelOwner,@ModelName)
set @Result=1
end
end

GO




ReadArt 获取文章的具体信息-阅读文章



create proc ReadArt
(
@ArtId int
)
as
begin
declare @temp int
select @temp=iBrowseCount+1 from Art where iArtId=@ArtId --浏览次数+1
update Art set iBrowseCount=@temp where iArtId=@ArtId
select iBrowseCount,tArtContent,cPubTime,vcArtName from Art where iArtId=@ArtId
end

GO





RegUser 添加新的用户



CREATE proc RegUser
(
@UserName char(10), --用户名
@UserPwd varchar(50), --密码
@UserNumber char(8) output --返回QQ号
)
as
begin
declare @temp char(8)
select @temp=max(cQQNum)+1 from UserInf
set @UserNumber=case
when len(@temp)=1 then '0000000'+@temp
when len(@temp)=2 then '000000'+@temp
when len(@temp)=3 then '00000'+@temp
when len(@temp)=4 then '0000'+@temp
when len(@temp)=5 then '000'+@temp
when len(@temp)=6 then '00'+@temp
when len(@temp)=7 then '0'+@temp
else @temp
end
insert into UserInf(cUserName,cQQNum,vcQuserPwd) values(@UserName,@UserNumber,@UserPwd)
exec CreateGroup @UserNumber,'我的好友'
return(@UserNumber)
end
GO




ReNameModel 重命名模块


create proc ReNameModel
(
@ModelId int,
@ModelName varchar(20)
)
as
begin
update ArtModule set vcModeName=@ModelName where iModeId=@ModelId
end

GO



SelectUserByName 通过用户名查询用户


CREATE proc SelectUserByName
(
@UserName varchar(10)
)
as
begin
select cUserName,cQQNum from UserInf where cUserName like '%'+@UserName+'%'
end
GO



SelectUserByNum 通过用户号码查询用户



create proc SelectUserByNum
(
@UserNum varchar(8)
)
as
begin
select cUserName,cQQNum from UserInf where cQQNum=@UserNum
end

GO





UpDateGroupInf 修改分组信息


CREATE proc UpDateGroupInf
(
@newName char(10),
@User char(8),
@GroupId int,
@Result int output
)
as
begin
if exists(select * from GroupInf where cGroupName=@newName and GroupOwner=@User)
begin
set @Result=0
end
else
begin
if exists(select * from GroupInf where cGroupName='我的好友' and iGroupId=@GroupId)
begin
set @Result=2
end
else
begin
update GroupInf set cGroupName=@newName where iGroupId=@GroupId
set @Result=1
end
end
end
Go

0 评论:

发表评论