在My sql ER图中创建复合属性? [英] Create a composite attribute in My sql ER diagram?

查看:136
本文介绍了在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.

这篇关于在My sql ER图中创建复合属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆