开发者

A way to mark special row in a big table

Context: SQL Server 2008, ASP.NET MVC 2.0

I have table that lists forum topics.

|TopicId|Subject|Author|Views|LastUpdate|

I have a special forum topic that I use as a home-page "news" list. Such that message from that forum topic are listed as news.

Now I need somehow to indicate which forum topic is the news.

Here are some options:

Add another column called |IsNewsForumTopic|, but this feels an overkill, since other 10000 forum topics will always have set it to false.

Store news-forum-topic in web.config and do select based on that (don't like this appro开发者_开发知识库ach also).

Use a database global variable in form of a storproc with NewsForumTopicId hardcoded.

Create NewsForumTopics table and manually add single record in there:

|NewsForumTopicId|
| 1174           |

I like this approach the most.

  1. it doesn't take DB specific information out of the DB.
  2. Doesn't affect big ForumTopics table.
  3. I can add another column |SpecialType| enum-column later to maybe have a separate forum-topic for news, updates, and bug fixes.

Please criticize and/or suggest.


This is a situation where, no matter how you look at it, you need a hard-coded value in your system. Key questions here are:

  • How likely is it to change over time?
  • How bad is it if it gets mis-set somehow? (Bad configuration, or you get hacked)

I generally store such values in the database as per your NewsForumTopics table, but I would not do that for data that should never change. If that is the case, either hard-coding it in a stored procedure or burying it in a application config file seems wisest.

(And then there's the question "how to prevent some joker from ever deleting that one special entry", but that's a security issue to ask in your next SO question.)


Er, how about a special Author? AuthorId = -1 or AuthorName = 'news_bot'. No schema changes involved.

If it is not too late in the project, you may also consider:

A way to mark special row in a big table

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜