【问题标题】:Best approach to go: one table for each operation or one table for all operations?最佳方法:每个操作一张表还是所有操作一张表?
【发布时间】:2014-10-28 18:14:44
【问题描述】:

我正在为解决方案设计数据库。我面临以下情况:

  • 用户可以添加产品。该产品将属于特定操作:“SELL”、“BUY”等。
  • 其他用户可以将产品标记为感兴趣。所以,我将有一个表格来生成对某事感兴趣的用户。

我正在努力决定采用哪种方法:

  1. 我可以为每个操作创建一个表,例如“ProductSell”、“ProductBuy”等。对于感兴趣的用户(“InterestedProductSell”、“InterestedProductBuy”等)也是如此。

```

User               ProductSell   ProductBuy   InterestBuy                 InterestSell
____________       ___________   __________   ___________                 ____________
Id                 Id            Id           ProductId (ProductBuy PK)   ProductId (ProductSell PK)
Name               Title         Title        UserId                      UserId
Username           UserId        UserId       Date                        Date

```

  1. 我可以为所有操作创建一个表,其中有一列名为“操作”。感兴趣的用户也一样。

```

User            Operation              Product       Interest
____________    _________              ___________   __________
Id              Id                     Id            ProductId (ProductBuy or ProductSell PK)        
Name            Name (Buy, sell, etc)  Title         UserId                     
Username                               UserId        Date      
                                       Operation   

```

您能否就这两种方法,甚至是我没有意识到的第三种方法发表您的看法?诸如性能、优化、维护、编码之类的事情……除了我的看法之外,我还需要其他选择。

如果有关系,我正在使用 SQL Server。

【问题讨论】:

    标签: sql-server database database-design


    【解决方案1】:

    您为 Operation 设置单独列的第二种方法看起来不错

    用户

    uid
    name
    

    产品

    pid
    name
    

    用户产品

    uid
    pid
    operation
    time
    

    【讨论】:

    • 雷达,感谢您的提示。方法与您的视线略有不同。请检查我上面的答案以查看我的域并了解我想要做什么。
    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 2018-12-24
    • 2016-03-12
    • 1970-01-01
    • 2011-03-14
    • 2011-04-30
    • 2014-01-31
    • 1970-01-01
    相关资源
    最近更新 更多