小型数据库实体的域和子域的概念
最近我学到了一个老师所说的“域和子域”的概念,其中概括了小表,其中将保存少于 5000 条数据或行,我向您展示一个示例:
实体
级别日期:
id_level description
01 continent
02 country
03 state
域日期
id_domain detail level parent
01 America 01 -
02 USA 02 01
03 Europe 01 -
04 Africa 01 -
05 UK 02 03
06 Aberdeen 03 05
<强>如果这个概念有另一个名字,了解它会对我有很大帮助。
然后我们必须对此进行抽象,并将其应用于常见实体,如下例所示:
级别日期:
id_level description
01 address
02 phone
03 gender
域日期
id_domain detail level parent
01 male 03 -
02 female 03 -
03 mobile phone 02 -
04 home address 01 -
05 home phone 02 -
06 work address 01 -
人员日期
id_person name phone_type phone_value address_type adress_value gender
01 Jhon 03 39249927 06 a place... 01
02 Mary 05 2489540300 04 a place2... 02
但我收到一条错误消息,提示重复密钥当我尝试建立关系时的名称
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_DOMAIN
FOREIGN KEY (address_type)
REFERENCES domain(id_domain);
错误
Duplicate key name 'FK_PERSON_DOMAIN'
我应该添加的是,我已经使用phone_type进行了嵌套,此后它不允许我将其他两个属性嵌套为如图所示
这是完美的关系:
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_DOMAIN
FOREIGN KEY (phone_type)
REFERENCES domain(id_domain);
recently I learned a concept called by my teacher "Domains and subdomains" in which small tables are generalized in which less than 5000 data or rows will be saved, I show you an example:
Entities
level dates:
id_level description
01 continent
02 country
03 state
domain dates
id_domain detail level parent
01 America 01 -
02 USA 02 01
03 Europe 01 -
04 Africa 01 -
05 UK 02 03
06 Aberdeen 03 05
If this concept has another name, it would help me a lot to know it.
Then we had to make an abstraction of this and take it to common entities like the following example:
level dates:
id_level description
01 address
02 phone
03 gender
domain dates
id_domain detail level parent
01 male 03 -
02 female 03 -
03 mobile phone 02 -
04 home address 01 -
05 home phone 02 -
06 work address 01 -
Person dates
id_person name phone_type phone_value address_type adress_value gender
01 Jhon 03 39249927 06 a place... 01
02 Mary 05 2489540300 04 a place2... 02
but i get an error saying, the duplicate key name when i try to make the relation
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_DOMAIN
FOREIGN KEY (address_type)
REFERENCES domain(id_domain);
Error
Duplicate key name 'FK_PERSON_DOMAIN'
Something I should add is that I already did the nesting with phone_type, after this it does not let me nest the other two attributes as shown in the diagram
This is the relationship that worked perfectly:
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_DOMAIN
FOREIGN KEY (phone_type)
REFERENCES domain(id_domain);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我称这些为“查找表”。它们通常具有行数较少的特点,并且不会经常更改。它们可能有一个整数
id
主键,或者它们可能有一个自然主键。关于重复键名称的错误是由约束名称在架构中的所有表中必须唯一的规则引起的。换句话说,架构中必须只有一个名为
FK_PERSON_DOMAIN_PERSON
的约束。您说您已经为
phone_type
列创建了一个具有此名称的约束。如果您希望address_type
列有另一个约束,则必须为该约束选择不同的名称。这是我的意思的一个例子:
看看约束名称是不同的。
I call those "lookup tables." They usually have characteristics of having a small number of rows, and also they don't change frequently. They may have an integer
id
primary key, or they may have a natural primary key.The error you got about the duplicate key name is caused by the rule that constraint names must be unique across all tables in a schema. In other words, there must be only one constraint named
FK_PERSON_DOMAIN_PERSON
in the schema.You said you already created a constraint with this name for the
phone_type
column. If you want another constraint for theaddress_type
column, you must choose a different name for that constraint.Here's an example of what I mean:
See that the constraint names are different.