在My sql ER图中创建复合属性?

问题描述:

我目前正在使用mySQL开发一个项目,我想知道mySQL是否可以为实体的属性创建一组复合属性.该属性不是主键,它是一个地址,因此应该将复合属性设置为街道,城镇,州ECT ... A)这可能吗?如果是这样,我将使用哪种类型/我将如何去做. B)如此实用,我大约有10个实体,我觉得其中的一些实体将需要复合属性,这只是最好的例子.

I am currently working on a project in mySQL and I was wondering if mySQL makes it possible to create a set of composite attributes for an attribute of an entity. The attribute is not the primary key, it is an address so the composite attributes are supposed to be, street, town, state ECT... A) is this possible? if so which type would I use/ how would I go about doing it. B) is this practical I have about 10 entities and I feel like a couple of them will need composite attributes that was just the best example.

否,MySQL不支持复合"属性.

No, MySQL doesn't support "composite" attributes.

您可以将"composite"属性的组成部分分解"到一个单独的表中.或者,您可以将它们作为单独的列保留在同一表中.

You could "break out" the components of the "composite" attribute into a separate table. Or, you can keep them as individual columns in the same table.

我使用列名来识别"组成复合属性的属性.您通过地址"给出了一个很好的例子.它确实是一个属性,由多个部分组成.

I use the column name to "identify" the attributes that make up a composite attribute. You gave a good example with "address". It really is one attribute, with several components.

这是我的一个表定义示例(已删除):

Here's a (neutered) example of one of my table definitions:

CREATE TABLE `foo` (
`id`              COMMENT 'PK'
`category_id`     COMMENT 'FK to ...'
`display_name`
...
`address_street`  
`address_street2` 
`address_city`    
`address_state`   
`address_country` 
`address_postal_code`
...
`country_code`    COMMENT 'ISO 3166-1-alpha-2 code'
`latitude`     
`longitude`    
...

最重要的是,MySQL不支持复合属性.但是我可以使用命名约定来将各个组件关联"起来.

Bottom line, MySQL doesn't support composite attributes. But I can use a naming convention to somewhat "relate" the components together.