如何在回复表中在回复

uscsndtuodnklds 2010-11-25 12:45:46

想知道数据库中的表是如何创建的
比如qq空间中发布了一个心情 别人回复后 我在回复别人的信息是 我的信息是放在回复表中还是在创建的另一张表
如下我自己想的解决方案是否可行 还有那个回帖数该怎么算?
create table Message --信息表
(
id int identity(1,1) primary key not null, --信息Id
title varchar(50) not null, --信息的标题
message varchar(500) not null, --信息的内容
author varchar(10) not null, --信息的作者
postTime datetime not null, --信息的发布时间
replyCount int not null, --信息的回复数
status int not null --信息的状态1:已读 0:未读
)
go

create table reply --回复 信息表中的信息的表
(
rid int identity(1,1) primary key not null, --回复的id
messageId int not null, --与信息表中的信息id对应
ruid int not null, --与用户表中的用户id对应
title varchar(50) null, --回复的标题
content varchar(500) not null, --回复的内容
rdate datetime not null, --回复的时间
)
go

create table rreply --回复 回复表中的信息的表
(
rrid int identity(1,1) primary key not null,
rid int not null, --与回复表中的回复id对应
rruid int not null, --与用户表中的用户id对应
rrcontent varchar(500) not null, --回复的内容
rrdate datetime not null --回复的时间


)
...全文
88 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenguang79 2010-11-26
  • 打赏
  • 举报
回复
一个表就行,
最简单的例子,就是楼主应该见过设计新闻的表吧
你只要在你现在表里加一个回复ID就行
这样就知道这个回复是对哪条留言回复的.如果这个为空就说明.他是对主新闻回复的
-晴天 2010-11-25
  • 打赏
  • 举报
回复
用不着这样吧,只要一个表就行了.
create table hf(id int,hfid int,hfnr nvarchar(100))
第一个发消息的 hfid 为空,
以后,每个回复都写上回复对象的id,作为hfid,
要查的时候只要把表自连接,hfid连上id就行了.
-晴天 2010-11-25
  • 打赏
  • 举报
回复
create table hf(id int,hfid int,hfnr nvarchar(100))
--最先发表
insert into hf select 1,null,'abcdef'
--对最先发表的回复
insert into hf select 2,1,'faofwa'
insert into hf select 3,1,'fwnfsadf'
--对回复的回复
insert into hf select 4,3,'wuinfwe'
insert into hf select 5,2,'fwifm'
--其间还有对最先发表的回复
insert into hf select 6,1,'fvawe'
--获取对发表的回复:
select * from hf where hfid in(select id from hf where hfid is null)
go
drop table hf
/*
id hfid hfnr
----------- ----------- ----------------------------------------------------------------------------------------------------
2 1 faofwa
3 1 fwnfsadf
6 1 fvawe

(3 行受影响)
*/
uscsndtuodnklds 2010-11-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wxf163 的回复:]
树状 记录父回复的ID即可
[/Quote]
说清楚点 不明白 最好给点代码是最好的
还有我上面的那个可行不?
王向飞 2010-11-25
  • 打赏
  • 举报
回复
树状 记录父回复的ID即可
2220728 2010-11-25
  • 打赏
  • 举报
回复
学习~~~~~~
uscsndtuodnklds 2010-11-25
  • 打赏
  • 举报
回复
那它的回复数量就是回复加上回复的数量啦 这不是我想要的 只有直接给它回复的才要

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧