I am currently designing a MySQL database that stores information pertaining to domains. Domain aliases belong to a domain, i.e. they have a parent, and so will reference a row from the same table in the parent field.
我目前正在设计一个MySQL数据库,用于存储与域有关的信息。域别名属于域,即它们具有父域,因此将引用父域中同一表的行。
domains
id | name | parent 1 | bob.com | NULL 2 | bobcompetition.com | 1
The problem here is that I'm purposely defining null based records for non-alias domains and also referencing a row within the same table might cause difficulties.
这里的问题是我故意为非别名域定义基于空的记录,并且在同一个表中引用一行可能会造成困难。
How would you suggest I model this data?
您如何建议我对此数据进行建模?
domains « domain_aliases
might be one way to go but domain aliases are domains. Essentially all domains should sit in the domains table, but I need a way to reference one domain to its 'parent' or 'primary' domain.
可能是一种方法,但域别名是域。基本上所有域都应该位于域表中,但我需要一种方法将一个域引用到其“父”或“主”域。
1 个解决方案
#1
2
Well, how about:
那么,怎么样:
Domains: ID, name
域名:ID,名称
and
Aliases: ParentId, ChildId
别名:ParentId,ChildId
(two foreign keys to the domains table)
(域表的两个外键)
This way all domains are in the domain table and you still have a way to find the relationship
这样所有域都在域表中,您仍然可以找到关系
#1
2
Well, how about:
那么,怎么样:
Domains: ID, name
域名:ID,名称
and
Aliases: ParentId, ChildId
别名:ParentId,ChildId
(two foreign keys to the domains table)
(域表的两个外键)
This way all domains are in the domain table and you still have a way to find the relationship
这样所有域都在域表中,您仍然可以找到关系