SQL 关系数据库中的术语“元组”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/751264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:43:09  来源:igfitidea点击:

What does the term "Tuple" Mean in Relational Databases?

sqlterminologyrdbmsdefinitiontuples

提问by Warrior

Please explain what is meant by tuples in sql?Thanks..

请解释sql中的元组是什么意思?谢谢..

回答by Jason Baker

Most of the answers here are on the right track. However, a row is not a tuple. Tuples*are unorderedsets of known values with names. Thus, the following tuples are the same thing (I'm using an imaginary tuple syntax since a relational tuple is largely a theoretical construct):

这里的大多数答案都在正确的轨道上。但是,行不是元组元组*是具有名称的已知值的无序集合。因此,以下元组是相同的(我使用的是虚构的元组语法,因为关系元组在很大程度上是一种理论结构):

(x=1, y=2, z=3)
(z=3, y=2, x=1)
(y=2, z=3, x=1)

...assuming of course that x, y, and z are all integers. Also note that there is no such thing as a "duplicate" tuple. Thus, not only are the above equal, they're the same thing. Lastly, tuples can only contain known values (thus, no nulls).

...当然假设 x、y 和 z 都是整数。还要注意,没有“重复”元组这样的东西。因此,以上不仅是相等的,而且是同一回事。最后,元组只能包含已知值(因此,没有空值)。

A row**is an ordered set of known or unknown values with names (although they may be omitted). Therefore, the following comparisons return false in SQL:

**是一组有序的已知或未知的值与名称(尽管它们可被省略)。因此,以下比较在 SQL 中返回 false:

(1, 2, 3) = (3, 2, 1)
(3, 1, 2) = (2, 1, 3)

Note that there are ways to "fake it" though. For example, consider this INSERTstatement:

请注意,虽然有一些方法可以“伪造”。例如,请考虑以下INSERT语句:

INSERT INTO point VALUES (1, 2, 3)

Assuming that x is first, y is second, and z is third, this query may be rewritten like this:

假设 x 是第一个,y 是第二个,z 是第三个,这个查询可以这样重写:

INSERT INTO point (x, y, z) VALUES (1, 2, 3)

Or this:

或这个:

INSERT INTO point (y, z, x) VALUES (2, 3, 1)

...but all we're really doing is changing the ordering rather than removing it.

...但我们真正要做的只是改变顺序而不是删除它。

And also note that there may be unknown values as well. Thus, you may have rows with unknown values:

还要注意,也可能存在未知值。因此,您可能有具有未知值的行:

(1, 2, NULL) = (1, 2, NULL)

...but note that this comparison will always yield UNKNOWN. After all, how can you know whether two unknown values are equal?

...但请注意,这种比较总是会产生UNKNOWN. 毕竟,你怎么知道两个未知值是否相等?

And lastly, rows may be duplicated. In other words, (1, 2)and (1, 2)may compare to be equal, but that doesn't necessarily mean that they're the same thing.

最后,行可能会重复。换句话说,(1, 2)and(1, 2)可能比较相等,但这并不一定意味着它们是一回事。

If this is a subject that interests you, I'd highly recommend reading SQL and Relational Theory: How to Write Accurate SQL Codeby CJ Date.

如果这是您感兴趣的主题,我强烈建议您阅读SQL 和关系理论:如何按 CJ 日期编写准确的 SQL 代码

*Note that I'm talking about tuples as they exist in the relational model, which is a bit different from mathematics in general.

*请注意,我说的是关系模型中存在的元组,这与一般的数学有点不同。

**And just in case you're wondering, just about everything in SQL is a row or table. Therefore, (1, 2)is a row, while VALUES (1, 2)is a table (with one row).

**以防万一您想知道,SQL 中的几乎所有内容都是行或表。因此,(1, 2)是一行,VALUES (1, 2)而是表(只有一行)。

UPDATE: I've expanded a little bit on this answer in a blog post here.

更新:我在这里的博客文章中对这个答案进行了一些扩展。

回答by Quassnoi

It's a shortened "N-tuple" (like in quadruple, quintupleetc.)

这是一个缩短的“ N-tuple”(如在quadruplequintuple等等)

It's a row of a rowset taken as a whole.

它是作为一个整体的行集的一行。

If you issue:

如果您发出:

SELECT  col1, col2
FROM    mytable

, whole result will be a ROWSET, and each pair of col1, col2will be a tuple.

,整个结果将是一个ROWSET,每对col1, col2都是一个tuple

Some databases can work with a tuple as a whole.

一些数据库可以作为一个整体使用元组。

Like, you can do this:

就像,你可以这样做:

SELECT  col1, col2
FROM    mytable
WHERE   (col1, col2) =
        (
        SELECT  col3, col4
        FROM    othertable
        )

, which checks that a whole tuplefrom one rowsetmatches a whole tuplefrom another rowset.

,它会检查一个整体tuple从一个rowset相匹配的整体tuple从另一个rowset

回答by vartec

In relational databases, tables are relations(in mathematical meaning). Relations are sets of tuples. Thus table row in relational database is tuple in relation.

关系数据库中,表是关系(在数学意义上)。关系是元组的集合。因此关系数据库中的表行是关系元组。

Wiki on relations:

关于关系的维基:

In mathematics (more specifically, in set theory and logic), a relation is a property that assigns truth values to combinations (k-tuples) of k individuals. Typically, the property describes a possible connection between the components of a k-tuple. For a given set of k-tuples, a truth value is assigned to each k-tuple according to whether the property does or does not hold.

在数学中(更具体地说,在集合论和逻辑中),关系是将真值分配给 k 个个体的组合(k 元组)的属性。通常,该属性描述了 k 元组的组件之间的可能连接。对于给定的一组 k 元组,根据属性是否成立,为每个 k 元组分配一个真值。

回答by user3177983

Whatever its use in mathematics, a tuple in RDBMS is commonly considered to be a row in a table or result set.?In an RDBMS a tuple is unordered. A?tuple in an MDDBMS is the instance of data in a cell with its associated dimension instances (members).

不管它在数学中的用途是什么,RDBMS 中的元组通常被认为是表或结果集中的一行。在 RDBMS 中,元组是无序的。MDDBMS 中的元组是单元格中的数据实例及其关联的维度实例(成员)。

What is the tuple in a column family data store?

列族数据存储中的元组是什么?

回答by mahendran krishnan

tuple = 1 record; n-tuple = ordered list of 'n' records; Elmasri Navathe book (page 198 3rd edition).

元组 = 1 条记录;n-tuple = 'n' 条记录的有序列表;Elmasri Navathe 书(第 198 页,第 3 版)。

record = either ordered or unordered.

记录 = 有序或无序。

回答by Bj?rn Kjos-Hanssen

As I understand it a table has a set K of keys and a typing function T with domain K. A row, or "tuple", of the table is a function r with domain K such that r(k) is an element of T(k) for each key k. So the terminology is misleading in that a "tuple" is really more like an associative array.

据我了解,一个表有一组键 K 和一个带有域 K 的打字函数 T。表的一行或“元组”是一个带有域 K 的函数 r,使得 r(k) 是 T 的一个元素(k) 对于每个密钥 k。因此该术语具有误导性,因为“元组”实际上更像是一个关联数组。

回答by veeramani

Tuples are known values which is used to relate the table in relational DB.

元组是已知值,用于关联关系数据库中的表。

回答by Chand

row from a database table

数据库表中的行

回答by rashedcs

Tuple is used to refer to a row in a relational database model. But tuple has little bit difference with row.

元组用于引用关系数据库模型中的一行。但是元组与行有一点区别。

回答by rashedcs

A tuple is used to define a slice of data from a cube; it is composed of an ordered collection of one member from one or more dimensions. A tuple is used to identify specific sections of multidimensional data from a cube; a tuple composed of one member from each dimension in a cube completely describes a cell value.

元组用于定义来自多维数据集的数据切片;它由来自一个或多个维度的一个成员的有序集合组成。元组用于从多维数据集中识别多维数据的特定部分;由多维数据集中每个维度的一个成员组成的元组完整地描述了一个单元格值。