如何在数据库中建模这个类? [英] How can I model this class in a database?

查看:67
本文介绍了如何在数据库中建模这个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一点帮助。这是我的设计,以组织几个类别。

 类别1 
子类别1.1
子类别1.1。 1
子类别1.2
子类别1.3

这将是一个集合。我想把它存储在一个数据库,但我不知道如何在数据库表中建模。我使用的是SQL Server CE。





UPDATE



我忘记将目标号码类(1.1,1.1.1)。

解决方案


$ b


  • 类别

    • id(主键,非空)



  • / ul>

    然后,如果类别有父级,则引用该另一行的 id 。所以表是自引用的。顶级类别有一个null parent_category_id



    建立这样的表格时, t创建循环引用。


    I need a little of help. This is my design to organize several categories.

       Category 1
         Sub Category 1.1
           Sub Category 1.1.1
         Sub Category 1.2
         Sub Category 1.3
    

    It would be a collection. I want to store it in a database, but I don't know how can I model it in a database table. I'm using SQL Server CE.

    UPDATE:

    I forgot put the objective number in the class (1.1, 1.1.1).

    解决方案

    You'd have a table something like this:

    • category
      • id (primary key, not null)
      • name (text, not null)
      • parent_category_id (foreign key to category.id, nullable)

    Then, if a category has a parent, you reference the id of that other row. So the table is self-referential. Toplevel categories have a null parent_category_id.

    When building tables like this you do need to be careful that you don't create a circular reference.

    这篇关于如何在数据库中建模这个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆