【发布时间】:2012-07-19 11:43:49
【问题描述】:
我认为 SO 和其他问答系统是高级 TSQL 技术的完美示例。我想知道 SO 和其他问题/答案系统如何与数据库表一起使用。我对什么是 TSQL 选择问题列表特别感兴趣,您还想在其中显示投票数和答案。
表 question 将被指定为这个
id int
title varchar
id_user int
table votes 这样您就可以监控用户对特定问题的投票
id_user int
id_question int
vote int
表格“答案”以及对问题的答复
id int
id_parent int
从question 获取结果的选择是什么样的:
id int
title varchar
votes_count int
answers_count int
我在考虑两种方法
- 表
question将在每次投票或回答时重新计算,并直接在question表中更新表字段votes_count和answers_count。这意味着表question也会有votes_count int, answers_count int - 创建将加入的选择,直接在
votes或answers表中计算count,并在question表中显示结果。每次选择所有投票和答案的记录都会损失多少速度?
谢谢。
【问题讨论】:
标签: sql tsql select join count