web-QQ(腾讯)-QZone-QQ日志-数据库设计

专题图ylbtech-asp.net编号:ylbtechASPNET

1,功能描述

   用户模块,日志模块,分类模块。

2,技术与环境

 

3,数据库设计

3.1  /App_Data/sql-basic.sql

-- =============================================
-- 仿QQ日志
-- author:YUANBO
-- development time:2011-8-4
-- =============================================
USE master
GO
-- Drop the database if it already exists
IF  EXISTS (
    SELECT name
        FROM sys.databases 
        WHERE name = N'QQ_Log'
)
DROP DATABASE QQ_Log
GO
CREATE DATABASE QQ_Log
GO
use QQ_Log
go
-- =============================================
-- 用户
-- =============================================
create table Users
(
UserID int identity(2000,1) primary key,    --编号
Email varchar(200), --邮箱
Username varchar(20) not null,          --昵称
Userpass varchar(20) not null   --密码
)
go
-- =============================================
-- 分类
-- =============================================
create table Category
(
CateID int identity(1,1) primary key, --编号
CateName varchar(20) not null,  --名称
Flag int default(0),        --1:代表个人日记;0:其他
UserID int foreign key references Users(UserID) --用户编号
)
go
-- =============================================
-- 日志
-- =============================================
create table RiZhi
(
RiZhiID int identity(1,1) primary key,  --编号
Title varchar(30) not null, --标题
Content ntext,              --内容
Pubdate datetime default(getdate()),    --发表时间
ViewCnt int default(0), --阅读次数
ReplyCnt int default(0),--评论次数
[Role] int default(0), --权限
UserID int foreign key references Users(UserID),    --用户编号
CateId int foreign key references Category(CateID)  --分类编号
)
go

3.2   /App_Data/insert.sql

View Code
use QQ_Log
go
--插入一些测数据
--1,Users
insert into Users(Username,Userpass) values('ylb','123');
go
--2,Category
insert into Category(CateName,UserID,flag) values('个人日记',2000,1);

 3.3  /App_Data/Select/1, Users.sql

View Code
use QQ_Log
go
-- =============================================
-- 用户功能模块的实现与方法
-- =============================================
go
--1,注册
Insert into Users(Username,Userpass) values('ylb','123');
select @@IDENTITY;
go
-----设置默认值
insert into Category(CateName,UserID,flag) values('个人日记',2000,1);

go
--2,登陆
select COUNT(*) from Users where UserID=2000 and Userpass='123';

go
--3,修改密码
---a)base,2
---b)
update Users set Userpass=321 where UserID=2000;

 3.4  /App_Data/Select/1, Category.sql

View Code
use QQ_Log
go
-- =============================================
-- 分类模块功能与实现
-- =============================================
go
--1,添加分类 
--要求:并把新添加的分类设为默认
insert into Category(CateName,UserID) values('ylb-Dream',2000);
select @@IDENTITY;

go
--2,删除一个分类
--要求:把给要删除该分类所有日志转到‘个人日记’分类中
select CateID from Category where UserID=2000 and Flag=1;
--CateID=2
--DelCateID=3
update RiZhi set CateID=2 where CateId=3;
go
delete Category where CateID=3;

go
--3,根据UserID获取分类列表
select CateID,CateName from Category where UserID=2001;

go
--4. 根据CateID获取分类名称
select CateName from Category where CateID=11;

--5,根据CateID修改分类名称
update Category set CateName='ddd' where CateID=11;

 3.5  /App_Data/Select/1, RiZhi.sql

View Code
use QQ_Log
go
-- =============================================
-- 日志功能模块的实现与方法
-- =============================================
--1,添加日记
insert into RiZhi(Title,Content,UserID,CateID) values('ylbzi','ylbzi',1,200);
select @@identity;

go
--2,查看单篇日记
--ylb 发表日期 阅读(1) 评论(0) 分类:个人日记 正文
--select * from RiZhi;

select RiZhiID,Title,Content,Pubdate,ViewCnt,ReplyCnt,c.CateID,CateName from RiZhi rz inner join Category c 
on rz.CateID=c.CateID
where RiZhiID=1;

go
--3,查看日记列表
select RiZhiID,Title,Pubdate,CateID,CateName,ViewCnt,ReplyCnt from RiZhi rz inner join Category c 
on rz.CateID=c.CateID
where c.UserID=2000;

go
--4,//统计用户写的日记数量
select count(*) from RiZhi where UserID=2000;
select count(*) from RiZhi where CateID=1;

go
---5,修改日记
update RiZhi set Title='ddd',Content='ccccc',CateID =2 where RiZhiID=1;

go
---7,日记浏览次数原基础加一
update RiZhi set ViewCnt=ViewCnt+1 where RiZhiID=1;

go
--8,根据分类去查日记
select RiZhiID,Title,Pubdate,CateID,CateName,ViewCnt,ReplyCnt from RiZhi rz inner join Category c 
on rz.CateID=c.CateID
where c.CateID=1;

go
--9,删除一条日记
delete RiZhi where RiZhiID=1;

go
---10,上一篇或下一篇
-----a)上一篇
select * from RiZhi order by RiZhiID asc;

select top 1 RiZhiID from RiZhi where RiZhiID <12 order by RiZhiID desc ;

-----b)下一篇
select top 1 RiZhiID from RiZhi where RiZhiID >12 order by RiZhiID asc ;
4,功能截图
4.1,

4.2,

4.3,

4.4,

4.5,

4.6,

4.7,

4.8,

4.9,

4.10,

 
5,代码分析

 解决方案属性图

6,示例|讲解案例下载

博客园讲解:  http://ylbtech.cnblogs.com/

百度文库开发文档: http://passport.baidu.com/?business&aid=6&un=ylbtech#7

谷歌开源代码下载: http://code.google.com/p/ylbtechopensource/downloads/list

请单击“QQ日志”

warn 作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 

最终目标

 代码的国际化标准示例 ylb,tech”,最大程度地规范软件编程开发统一,优质, 高效,易学,为建设软件强国(中国)而努力。

 

posted on 2012-09-07 11:21  ylbtech  阅读(1575)  评论(3编辑  收藏  举报