使用冗余关系是不好的吗? [英] Is it bad to use redundant relationships?

查看:130
本文介绍了使用冗余关系是不好的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的数据库中有以下表格:

Suppose I have the following tables in my database:

表http://www.freeimagehosting.net/uploads/a5ef036857.png

现在我的所有查询都取决于公司表。给每个其他表与公司表(冗余)关系以简化我的sql查询是不好的做法吗?

Now all my queries depend on Company table. Is it a bad practice to give every other table a (redundant) relationships to the Company table to simplify my sql queries?

编辑1:背景是框架的使用问题。请参见 Django:限制模型数据

Edit 1: Background is a usage problem with a framework. See Django: limiting model data.

编辑2:没有元组会改变他的公司。

Edit 2: No tuple would change his company.

mysql查询。我使用抽象层(django)。

Edit 3: I don't write the mysql queries. I use a abstraction layer (django).

推荐答案

这是坏的做法,因为你的冗余数据必须独立更新, 。一个充满潜在的错误的过程。 (即使自动级联必须单独分配和维护)

It is bad practice because your redundant data has to be updated independently and therefore redundantly. A process that is fraught with potential for error. (Even automatic cascading has to be assigned and maintained separately)

通过引入此关系,您可以有效地对数据库进行非规范化。非正规化有时需要为了性能,但从你的问题听起来你只是简化你的SQL。

By introducing this relation you effectively denormalize your database. Denormalization is sometimes necessary for the sake of performance but from your question it sounds like you're just simplifying your SQL.

使用其他机制来抽象数据库的复杂性:视图,存储的程序,UDF

Use other mechanisms to abstract the complexity of your database: Views, Stored Procs, UDFs

这篇关于使用冗余关系是不好的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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