gpt4 book ai didi

php - 具有 UNIQUE INDEX MySQL 和 NULL 列的重复行

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:51 26 4
gpt4 key购买 nike

表后缀:身份证、姓名

(3, 'com')

表域名:身份证、姓名

(2, 'microsoft')

表域:id、name_code、后缀

(1, 2, 3)    -- microsoft.com

表子域名:

(4, 'windows')

表子域:id、name_code、域

(7, 4, 1)     -- windows.microsoft.com

表格电子邮件:id, name, atserver

(3, 'myemail', 7)    -- myemail@windows.microsoft.com
(4, 'other', 1) -- other@microsoft.com

这里是一个外键约束的问题。如何解析域和子域以正确创建电子邮件?我在使用 NULL 值的 Unique INDEX 时遇到问题,例如,解决方案可能是:

表格电子邮件:id、名称、子域、域

(3, 'myemail', 7, NULL)  -- myemail@windows.microsoft.com
(4, 'other', NULL, 1) -- other@microsoft.com

但是

(5, 'newemail', NULL, NULL)  -- will duplicated values in the table
(6, 'newemail', NULL, NULL)
(7, 'newemail', NULL, NULL)
(8, 'newemail', NULL, NULL)

(**3**, 'myemail', 7, 1)   -- myemail@windows.microsoft.com and myemail@microsoft.com

最佳答案

怎么样 (5, 'newemail', domain_id/subdomain_id, 'domain/subdomain')

所以你可以

(5, 'newemail', 7, '子域') 或 (5, 'newemail', 1, '域')

您仍然可以 LEFT JOIN SubDomain 和 Domain 表,但您只会根据“域/子域”字段从您需要的数据中获取数据。

这是快速解决方案。恕我直言,您的数据库结构不是很好,可以优化。您应该将所有域/子域记录保存在一个表中并将其用于电子邮件。该表应该是 Table FullDomain: id, name_code, domain_name, subdomain_name


(1, 3, 2, 4) -- windows.microsoft.com


(1, 3, 2, 0) -- microsoft.com

关于php - 具有 UNIQUE INDEX MySQL 和 NULL 列的重复行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4497974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com