数据库设计变量字段 [英] Database design variable amount of fields

查看:163
本文介绍了数据库设计变量字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户制作一个网站,但我偶然发现了一个问题,我需要一些建议。

I'm making a website for a client but I stumbled upon a problem and I need some advice on it.

对于每个项目,他们希望拥有设置可变数量的图像和(有时)一些相应文本的可能性。

For each project, they want to have the possibility to set a variable amount of images and (sometimes) some corresponding text.

我正在考虑将所有信息存储在一个字段中,而不是将field_1映射到field_99以防万一他们需要99个字段。

I was thinking about storing all of the information in one field, instead of making field_1 to field_99 just in case they need 99 fields.

// database column

'../fotos/foto1.png',
'hier komt tekst',
'../fotos/foto2.png',
'', (empty text)
'../fotos/foto3.png'

此解决方案有一些不利之处,必须有更好的方式实现这一点。

This solution has some disadvantadges, there must be better manners out there to achieve this.

这样做的首选方法是什么?

What's the preferred way to do this?

推荐答案

创建另一个表(例如FOTO_CODES),其中包含所有可能的foto值,并为其生成id

Create another table (e.g. FOTO_CODES) with all possibly values of foto and generate id for them.

创建另一个子表,它将具有来自FOTO_CODES表和FOTO数据(Image)的主表记录ID和ID。

Create another child table that will have the master table record id and ID from FOTO_CODES table and FOTO data (Image).

标准化。

这篇关于数据库设计变量字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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