【问题标题】:Proper way to make this data dictionary制作此数据字典的正确方法
【发布时间】:2014-01-17 10:27:08
【问题描述】:

我对创建数据字典的正确方法有疑问。 我以前从未这样做过,但现在我必须这样做。

此时我要数据表:

public class Device
{
    public int DeviceId { get;set; }
    public string DeviceSerialNumber { get; set; }
    [Required]
    [StringLength(14)]
    public string DeviceUser { get; set; }
    public int DeviceDictionaryId { get; set; }
    [ForeignKey("DeviceDictionaryId")]
    public virtual DeviceDictionary DeviceDictionary {get;set;}
    public string Batch { get; set; }
}

我的字典用于创作目的:

public class DeviceDictionary
{      
    public int DeviceDictionaryId { get; set; }
    [Required]
    public string DeviceManufacturer { get; set; }
    [Required]
    public string DeviceName { get; set; }
}

现在是我的问题。

我做的设计是好的还是我应该做一些改变?我考虑将 DeviceDictionary 拆分为 2 个新表:Manufactures 和 DeviceName 与外键 ManufacturerId 连接。

谁能建议我哪种方式更适合我的简单解决方案?

【问题讨论】:

  • 也许你应该添加标签你正在使用什么数据库,这样你就可以吸引更多来自该社区的人
  • @vasin1987,这个问题几乎与数据库引擎无关。

标签: c# sql-server database-design


【解决方案1】:

Manufactures 和 DeviceName 与外键 ManufacturerId 关联

是的,你需要再分解一下。您将需要一个设备表:

CREATE TABLE Device ( Id, Name, ManufacturerId )

注意:以上及以下均为伪代码,无法编译。)

还有一张供制造商使用的表格:

CREATE TABLE Manufacturer ( Id, Name )

由于每台设备只有一个制造商,因此您不需要多对多的表格。

【讨论】:

  • 谢谢。但在我的情况下,不可能有许多制造商会制造相同的设备。数据库将用于制作 dell e5000、samsung s2 等物品的列表
  • @szpic,然后只需将ManufacturerId 移动到Device 表中并删除DeviceDictionary 表。
  • 所以你建议把它全部放在一张桌子上还是什么?我现在有点困惑
猜你喜欢
  • 1970-01-01
  • 2015-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多