热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

db视图和lookuptable之间的区别-Differencebetweenadbviewandalookuptable

WhenIcreateaviewIcanbaseitonmultiplecolumnsfromdifferenttables.WhenIwanttocreate

When I create a view I can base it on multiple columns from different tables. When I want to create a lookup table I need information from one table, for example the foreign key of an order table, to get customer details from another table. I can create a view having parameters to make sure it will get all data that I need. I could also - from what I have been reading - make a lookup table. What is the difference in this case and when should I choose for a lookup table?? I hope this ain't a bad question, I'm not very into db's yet ;).

当我创建一个视图时,我可以将它基于来自不同表的多个列。当我想创建一个查找表时,我需要来自一个表的信息,例如订单表的外键,以从另一个表中获取客户详细信息。我可以创建一个具有参数的视图,以确保它将获得我需要的所有数据。我也可以 - 从我一直在阅读的内容 - 制作一个查找表。在这种情况下有什么区别,我何时应该选择查找表?我希望这不是一个糟糕的问题,我不是很喜欢db的;)。

5 个解决方案

#1


2  

I think your usage of "Lookup Table" is slightly awry. In normal parlance a lookup table is a code or reference data table. It might consist of a CODE and a DESCRIPTION or a code expansion. The purpose of such tables is to provide a lsit of permitted values for restricted columns, things like CUSTOMER_TYPE or PRIORITY_CODE. This category of table is often referred to as "standing data" because it changes very rarely if at all. The value of defining this data in Lookup tables is that they can be used in foreign keys and to populate Dropdowns and Lists Of Values.

我认为你对“查找表”的使用有点不对劲。按照通常的说法,查找表是代码或参考数据表。它可能包含CODE和描述或代码扩展。这些表的目的是为受限制的列提供lsit允许值,例如CUSTOMER_TYPE或PRIORITY_CODE。这类表通常被称为“常设数据”,因为它很少发生变化。在Lookup表中定义此数据的值是,它们可以在外键中使用,并填充Dropdown和Lists Of Values。

What you are describing is a slightly different scenario:

你所描述的是一个略有不同的场景:

I need information from one table, for example the foreign key of an order table, to get customer details from another table

我需要来自一个表的信息,例如订单表的外键,以从另一个表中获取客户详细信息

Both these tables are application data tables. Customer and Order records are dynamic. Now it is obviously valid to retrieve additional data from the Customer table to display along side the Order data, and in that sense Customer is a "lookup table". More pertinently it is the parent table of Order, because it has the primary key referenced by the foreign key on Order.

这两个表都是应用程序数据表。客户和订单记录是动态的。现在,从Customer表中检索附加数据以显示Order数据旁边显然是有效的,从这个意义上说,Customer是一个“查找表”。更有针对性的是它是Order的父表,因为它具有Order上的外键引用的主键。

By all means build a view to capture the joining logic between Order and Customer. Such views can be quite helpful when building an application that uses the same joined tables in several places.

通过所有方式构建一个视图来捕获Order和Customer之间的连接逻辑。在构建在多个位置使用相同连接表的应用程序时,此类视图非常有用。

#2


2  

Creating a view gives you a "live" representation of the data as it is at the time of querying. This comes at the cost of higher load on the server, because it has to determine the values for every query. This can be expensive, depending on table sizes, database implementations and the complexity of the view definition.

创建视图会为您提供查询时的“实时”数据表示。这是以服务器上的更高负载为代价的,因为它必须确定每个查询的值。这可能很昂贵,具体取决于表大小,数据库实现和视图定义的复杂性。

A lookup table on the other hand is usually filled "manually", i. e. not every query against it will cause an expensive operation to fetch values from multiple tables. Instead your program has to take care of updating the lookup table should the underlying data change.

另一方面,查找表通常是“手动”填充,即。即并非每个针对它的查询都会导致昂贵的操作从多个表中获取值。相反,如果基础数据发生变化,您的程序必须负责更新查找表。

Usually lookup tables lend themselves to things that change seldomly, but are read often. Views on the other hand - while more expensive to execute - are more current.

通常查找表适合于很少改变但经常阅读的内容。另一方面,观点 - 虽然执行成本更高 - 更新。

#3


0  

Read this tutorial and you may find helpful info when a lookup table is needed:

阅读本教程,您可以在需要查找表时找到有用的信息:

SQL: Creating a Lookup Table

SQL:创建查找表

#4


0  

Here's an example of a lookup table. We have a system that tracks Jurors, one of the tables is JurorStatus. This table contains all the valid StatusCodes for Jurors:

这是一个查找表的示例。我们有一个跟踪陪审员的系统,其中一个表是JurorStatus。此表包含陪审团的所有有效StatusCodes:

Code: Value
WS : Will Serve
PP : Postponed
EM : Excuse Military
IF : Ineligible Felon

代码:价值WS:将服务PP:推迟EM:借口军事IF:不合格的Felon

This is a lookup table for the valid codes.

这是有效代码的查找表。

A view is like a query.

视图就像一个查询。

#5


0  

Just learn to write sql queries to get exactly what you need. No need to create a view! Views are not good to use in many instances, especially if you start to base them on other views, when they will kill performance. Do not use views just as a shorthand for query writing.

只需学习编写SQL查询即可获得所需内容。无需创建视图!在许多情况下使用视图并不好用,特别是如果你开始将它们放在其他视图上,那么它们会破坏性能。不要将视图用​​作查询编写的简写。


推荐阅读
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 本文介绍了如何在 DB2 环境中创建和删除数据库编目。创建编目是连接新数据库的必要步骤,涉及获取数据库连接信息、使用命令行工具进行配置,并验证连接的有效性。删除编目则用于移除不再需要的数据库连接。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
  • 本文深入探讨 MyBatis 中动态 SQL 的使用方法,包括 if/where、trim 自定义字符串截取规则、choose 分支选择、封装查询和修改条件的 where/set 标签、批量处理的 foreach 标签以及内置参数和 bind 的用法。 ... [详细]
  • 深入解析Spring Cloud Ribbon负载均衡机制
    本文详细介绍了Spring Cloud中的Ribbon组件如何实现服务调用的负载均衡。通过分析其工作原理、源码结构及配置方式,帮助读者理解Ribbon在分布式系统中的重要作用。 ... [详细]
  • 本文详细介绍了如何构建一个高效的UI管理系统,集中处理UI页面的打开、关闭、层级管理和页面跳转等问题。通过UIManager统一管理外部切换逻辑,实现功能逻辑分散化和代码复用,支持多人协作开发。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • 本文详细解析了Python中的os和sys模块,介绍了它们的功能、常用方法及其在实际编程中的应用。 ... [详细]
  • 本文详细介绍了 Apache Jena 库中的 Txn.executeWrite 方法,通过多个实际代码示例展示了其在不同场景下的应用,帮助开发者更好地理解和使用该方法。 ... [详细]
author-avatar
手机用户2502876011
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有