Create a composite attribute in My sql ER diagram?

时光总嘲笑我的痴心妄想 提交于 2020-02-04 05:52:05

问题


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.


回答1:


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

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`    
...

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



来源:https://stackoverflow.com/questions/23396988/create-a-composite-attribute-in-my-sql-er-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!