Please explain what is meant by tuples in sql?Thanks..
请解释sql中的元组是什么意思?
10 个解决方案
#1
72
Most of the answers here are on the right track. However, a row is not a tuple. Tuples*
are unordered sets 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:
row**是已知或未知值的有序集合(尽管它们可能被省略)。因此,下面的比较在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 INSERT
statement:
注意,有一些方法可以“假装”。例如,考虑这个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?
…但是请注意,这种比较总是会产生未知的结果。毕竟,你怎么知道两个未知的值是相等的呢?
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)和(1,2)可以比较相等,但这并不一定意味着它们是相同的。
If this is a subject that interests you, I'd highly recommend reading SQL and Relational Theory: How to Write Accurate SQL Code by 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)是一行,而值(1,2)是一个表(有一行)。
UPDATE: I've expanded a little bit on this answer in a blog post here.
更新:我在这里的一个博客文章中对这个答案进行了一些扩展。
#2
14
It's a shortened "N-tuple
" (like in quadruple
, quintuple
etc.)
它是一个缩短的“n元组”(如四倍、五倍等)。
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, col2
will be a tuple
.
整个结果将是一个行集,每一对col1, col2将是一个元组。
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 tuple
from one rowset
matches a whole tuple
from another rowset
.
,它检查从一个行集的一个完整的元组与另一个行集的整个元组匹配。
#3
4
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-tuple)分配真值。通常,属性描述k元组的组件之间可能的连接。对于给定的k元组集合,根据属性是否保留,将一个真值分配给每个k元组。
#4
3
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中的元组通常被认为是表或结果集中的一行。MDDBMS中的一个元组是一个具有关联维实例(成员)的单元中的数据实例。
What is the tuple in a column family data store?
在一个列家庭数据存储中,元组是什么?
#5
2
tuple = 1 record; n-tuple = ordered list of 'n' records; Elmasri Navathe book (page 198 3rd edition).
元组= 1记录;n-tuple = 'n'记录的有序列表;Elmasri Navathe book(第198页第3版)。
record = either ordered or unordered.
记录=有序或无序。
#6
0
row from a database table
从数据库表中的行。
#7
0
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 T和连续域K或元组,域的表是一个函数r K,T的r(K)是一个元素为每个关键K(K)。这个术语是误导,因为一个“元组”是真的更像一个关联数组中。
#8
0
Tuple is used to refer to a row in a relational database model. But tuple has little bit difference with row.
Tuple用于引用关系数据库模型中的一行。但是tuple与row有一点不同。
#9
-1
Tuples are known values which is used to relate the table in relational DB.
元组是已知值,用于将表关联到关系数据库中。
#10
-2
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.
元组用于从多维数据集定义数据块;它由一个或多个维度的一个成员的有序集合组成。元组用于从多维数据集识别多维数据的特定部分;多维数据集中的每个维度中的一个成员组成的元组,完全描述了一个单元格值。
#1
72
Most of the answers here are on the right track. However, a row is not a tuple. Tuples*
are unordered sets 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:
row**是已知或未知值的有序集合(尽管它们可能被省略)。因此,下面的比较在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 INSERT
statement:
注意,有一些方法可以“假装”。例如,考虑这个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?
…但是请注意,这种比较总是会产生未知的结果。毕竟,你怎么知道两个未知的值是相等的呢?
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)和(1,2)可以比较相等,但这并不一定意味着它们是相同的。
If this is a subject that interests you, I'd highly recommend reading SQL and Relational Theory: How to Write Accurate SQL Code by 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)是一行,而值(1,2)是一个表(有一行)。
UPDATE: I've expanded a little bit on this answer in a blog post here.
更新:我在这里的一个博客文章中对这个答案进行了一些扩展。
#2
14
It's a shortened "N-tuple
" (like in quadruple
, quintuple
etc.)
它是一个缩短的“n元组”(如四倍、五倍等)。
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, col2
will be a tuple
.
整个结果将是一个行集,每一对col1, col2将是一个元组。
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 tuple
from one rowset
matches a whole tuple
from another rowset
.
,它检查从一个行集的一个完整的元组与另一个行集的整个元组匹配。
#3
4
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-tuple)分配真值。通常,属性描述k元组的组件之间可能的连接。对于给定的k元组集合,根据属性是否保留,将一个真值分配给每个k元组。
#4
3
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中的元组通常被认为是表或结果集中的一行。MDDBMS中的一个元组是一个具有关联维实例(成员)的单元中的数据实例。
What is the tuple in a column family data store?
在一个列家庭数据存储中,元组是什么?
#5
2
tuple = 1 record; n-tuple = ordered list of 'n' records; Elmasri Navathe book (page 198 3rd edition).
元组= 1记录;n-tuple = 'n'记录的有序列表;Elmasri Navathe book(第198页第3版)。
record = either ordered or unordered.
记录=有序或无序。
#6
0
row from a database table
从数据库表中的行。
#7
0
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 T和连续域K或元组,域的表是一个函数r K,T的r(K)是一个元素为每个关键K(K)。这个术语是误导,因为一个“元组”是真的更像一个关联数组中。
#8
0
Tuple is used to refer to a row in a relational database model. But tuple has little bit difference with row.
Tuple用于引用关系数据库模型中的一行。但是tuple与row有一点不同。
#9
-1
Tuples are known values which is used to relate the table in relational DB.
元组是已知值,用于将表关联到关系数据库中。
#10
-2
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.
元组用于从多维数据集定义数据块;它由一个或多个维度的一个成员的有序集合组成。元组用于从多维数据集识别多维数据的特定部分;多维数据集中的每个维度中的一个成员组成的元组,完全描述了一个单元格值。