我是否应该为此在数据库中创建一个新表? [英] Should I create a new table into my database for this?

查看:98
本文介绍了我是否应该为此在数据库中创建一个新表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,除其他表外,还有products.产品表包含ID,名称,说明和有关该产品的其他一些数据.我还要添加一个类别.

On my database I have among other tables, products. Products table contains the id, name, description and some other data about the product. I want to add also a category.

我应该创建一个名为category的新表,并使用id和每个类别的名称,并在products中添加一个* category_id *来引用category的ID,否则我应该使用products的每一行上类别的名称?

Should I create a new table named category with and id and the name of each category, and have into the products a *category_id* that will refers to the id of category, or should I have the name of the category on each row of products ?

在第一种情况下,我将必须使用JOIN.这会对性能产生严重影响吗?

On the first case I will have to use JOIN. Will this have a serious impact on the performance?

推荐答案

通过在自己的表中定义类别,您可以:

By defining the categories in their own table you can:

  • 重命名类别
  • 动态生成类别列表以供选择
  • 添加类别描述
  • 添加新类别

…等等,而不必每次修改它们都更新与类别相关的代码.

… and so on, without having to update every bit of category related code each time you modify them.

是的,添加一个表.

这会对性能产生严重影响吗?

Will this have a serious impact on the performance?

可能不是.

这篇关于我是否应该为此在数据库中创建一个新表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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