简体   繁体   English

需要有关数据库表关系的帮助!

[英]need help with database table relationships!

I am trying to build a site which is a bit similar to this site. 我正在尝试建立一个与此网站有点相似的网站。 Basically i have established four tables: 基本上我已经建立了四个表:

  1. Users 用户数
  2. Threads 线程数
  3. Comments 评论
  4. Topics 主题

The way the relationships should be established: 建立关系的方式:

A user has got many comments. 用户有很多评论。
A user has got many threads. 用户有很多线程。
Each Thread has got its own theme,topic,subtopic (Topics table, which i use basically as tags). 每个线程都有自己的主题,主题,子主题(主题表,我基本上将其用作标签)。

The way that the database should work: 数据库的工作方式:
i want to use the sql command INSERT INTO() in my code, in various stages..but generally here is the description: 我想在我的代码中的各个阶段中使用sql命令INSERT INTO() 。.但是通常这里是说明:
When the user registers his : ID is set, name, pass, email obtained. 用户注册时,将设置:ID,名称,通行证,电子邮件。 (insert into User table) (插入用户表)
When he submits a question ThreadID is set, question title and paragraph inserted into the thread table (Thread table). 当他提交问题时,将设置ThreadID,将问题标题和段落插入线程表(Thread table)。
All threads are being generated on a page by the date (i put a special field in the thread table). 所有线程都按日期在页面上生成(我在线程表中放了一个特殊字段)。
The comment table acts the way thread works, but it also has got ta comment response field. 注释表充当线程工作的方式,但是它也有一个注释响应字段。

Here is the layout: 这是布局:

Users 用户数

UserID (primarty key: Linked to comments and threads).
Login
Password
Email

Threads 线程数

ThreadID (primary key: linked to Comments Table)
UserID
TopicsID
Comments
Date
ThreadTitle
ThreadParagraph(question details)

Comments 评论

CommentsID (primary key: didnt link it to any other field in any other table)
UsersID
ThreadsID
Date
Comments
CommentResponse

Topics 主题

TopicsID (primary key: linked to Threads table)
Theme
Topic
Subtopic

The idea behind the design: 设计背后的想法:
Every user has many comments and threads that he can modify. 每个用户都有许多可以修改的注释和主题。
The topics are used as tags (i will link them to 3 drop down lists later on). 主题用作标签(稍后将它们链接到3个下拉列表)。
Each thread has got many comments. 每个线程都有很多评论。
Each comment has got comment response/s. 每个评论都有评论回复。

I am new to building a database. 我是建立数据库的新手。 i read a bit on how to build table relationships and database. 我阅读了一些有关如何建立表关系和数据库的信息。 but before i deploy everything, i need your advice on the improvements that i could make? 但是在部署所有内容之前,我需要您对我可以做出的改进的建议吗? and general opinion on the design!!! 和对设计的一般意见!

ps. ps。 i use c#, asp.net, visual studio 2010 我使用C#,asp.net,Visual Studio 2010

For the most part I think your design is fine. 在大多数情况下,我认为您的设计很好。 However, I would suggest normalising the Topics table by either making separate tables for the themes, topics and sub topics, or creating a self referencing table: 但是,我建议通过为主题,主题和子主题创建单独的表或创建自引用表来规范Topics表:

Topics 主题

TopicID (int, primary key, not null)
ParentTopicID (int, null)
Name (nvarchar(50), not null)

This will make for a more efficient use of storage (you're no longer duplicating theme and topic names in your data) and give you more flexibility (you can have infinite levels of hierarchical tags with this design). 这样可以更有效地利用存储空间(您不再在数据中重复主题和主题名称),并为您提供了更大的灵活性(通过这种设计,您可以拥有无​​限级别的层次标记)。

Also, it's unnecessary to prefix column names with the name of the table, eg Threads.ThreadTitle. 同样,也不必在表名前加上列名,例如Threads.ThreadTitle。 In this case I would recommend renaming Threads.ThreadTitle to Threads.Title and Threads.ThreadParagraph to Threads.Paragraph. 在这种情况下,我建议将Threads.ThreadTitle重命名为Threads.Title,并将Threads.ThreadParagraph重命名为Threads.Paragraph。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM