【问题标题】:Database Design - Which design should I use? Two options数据库设计 - 我应该使用哪种设计?两种选择
【发布时间】:2011-02-10 02:21:50
【问题描述】:

我正在使用 PostgreSQL 设计数据库模式。我对应该使用哪种设计有些疑问。

表tdir_details_uris_text 将有数百万个寄存器,每个键domain、uri、id_language 将有大约10/20 个寄存器。

哪种设计应该表现良好?三桌设计还是两桌设计?

最好的问候,

PS:对不起我的英语不好。


更新:只是添加一个 INSERT INTO 示例

insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'title_webpage', '1', '2009 Ford Mustang GT');
insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'highlights', '1', 'No Accidents / Damage Reported to CARFAX');
insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'highlights', '2', 'No Airbag Deployment Reported to CARFAX');
insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'highlights', '3', 'Vehicle Qualifies for the CARFAX Buyback Guarantee');
insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'highlights', '4', 'No Structural/Frame Damage Reported to CARFAX');
insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'highlights', '5', 'No Manufacturer Recalls Reported to CARFAX');
insert into tdir_details_uris_text (domain, uri, id_language, id_categorie, id_data, id_ordinal, n_text) values ('motors.shop.ebay.com', 'http://cgi.ebay.com/ebaymotors/2009-FORD-MUSTANG-GT-BLACK-BEAUTY-16K-MILES-WOW-/230580626087?pt=US_Cars_Trucks&hash=item35afad22a7', 'en', '23', 'highlights', '6', 'No Indication of an Odometer Rollback');

【问题讨论】:

  • 真正的问题是:哪种设计更适合模型和关系代数?总是从那里开始。
  • 在 tdir_detauls_uris_text 和 tdir_uris_text 中有 domain/url/id_language 的原因吗?乍一看,这似乎是模型中的一个缺陷。无论如何,我不确定要呈现的真正“模型”。是一对多还是多对多等?确保满足该要求。

标签: database-design postgresql


【解决方案1】:

听起来像是多对多的关系,需要三表设计。

但我不认为这是你展示的设计。我没有看到正确的主键关系。

表 A 将 ID_A 作为主键。

表 B 将 ID_B 作为主键。

JOIN 表 AB 会有主键 ID_A、ID_B;每个都是表 A 和 B 的外键。

【讨论】:

  • 您好,感谢您的回复。我已经更新了一个 INSERT INTO 示例。哪个表的主键不正确?最好的问候,
【解决方案2】:

选项 1 中的“tdirs_uris_text”表没有我能看到的用途(如果您的整个设计中只有这两个表)。要问的问题是“tdirs_uris_text”中的主键是否会在不同的表上多次使用(作为外键)。具体来说,是否会出现“详细信息”表多次出现“uris”外键的情况?如果是,则选项 1 更好,否则首选选项 2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    • 2011-10-30
    • 1970-01-01
    相关资源
    最近更新 更多