MySQL数据库中的单列存储多个值? [英] multiple value stored in single coloumn in MySQL database?

查看:376
本文介绍了MySQL数据库中的单列存储多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一个属性中存储多个值。
例如:
列名称:电话
i想在一列(电话)一行中存储5,7和16这三个不同的值。

How can i store multiple values in one attribute. for example: column name: telephone i want to store 5,7 and 16 this three different values in one column (telephone) in one row.

推荐答案

你不应该这样做。它显示DB没有被正确设计。

You should not be doing that. It goes to show that the DB has not been designed properly.

但是,如果你不用改变你的数据库设计就行了。您可以使用特殊胶水加入所有电话号码,确保不会成为任何电话号码的一部分,例如。所以5,7和16将全部存储在varchar类型的一列中,作为 5%7%16 ,稍后应用程序将其根据需要进行分割。

But if you have to do it without altering your DB design. You can join all the telephone numbers with a special glue, which is ensured not to be part of any telephone number, something like %. So 5, 7 and 16 will all be stored in one column of type varchar as 5%7%16, later your application and split them up as needed.

这篇关于MySQL数据库中的单列存储多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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