术语“元组”是什么意思? 在关系数据库中意味着什么?

发布于 2024-07-17 00:45:43 字数 29 浏览 5 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

草莓酥 2024-07-24 00:45:43

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

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

...当然假设 x、y 和 z 都是整数。 另请注意,不存在“重复”元组之类的东西。 因此,以上不仅是相同的,而且是相同的东西。 最后,元组只能包含已知值(因此不能包含空值)。

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

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

但请注意,有一些方法可以“伪造”它。 例如,考虑这个 INSERT 语句:

INSERT INTO point VALUES (1, 2, 3)

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

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

或者这样:

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

...but all we're real所做的是改变顺序而不是删除它。

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

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

...但请注意,此比较将始终产生 UNKNOWN。 毕竟,您如何知道两个未知值是否相等?

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

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

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

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

更新:我在博客文章中对此答案进行了一些扩展此处

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).

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:

(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 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:

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.

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.

* 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).

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

椒妓 2024-07-24 00:45:43

它是一个缩短的“N 元组”(如四元组五元组 等),

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

如果您发出:

SELECT  col1, col2
FROM    mytable

,整个结果将是一个ROWSET,并且每对col1,col2将是一个元组

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

例如,您可以执行以下操作:

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

,它检查一个 rowset 中的整个 tuple 是否与另一个 rowset 中的整个 tuple 匹配代码>.

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

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.

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.

和影子一齐双人舞 2024-07-24 00:45:43

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

维基百科关于关系:

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

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.

只涨不跌 2024-07-24 00:45:43

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

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

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).

What is the tuple in a column family data store?

可爱咩 2024-07-24 00:45:43

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

记录 = 有序或无序。

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

record = either ordered or unordered.

泛泛之交 2024-07-24 00:45:43

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

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.

人事已非 2024-07-24 00:45:43

数据库表中的行

row from a database table

尘世孤行 2024-07-24 00:45:43

<块引用>

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

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

裸钻 2024-07-24 00:45:43

元组用于引用关系数据库模型中的行。 但元组与行几乎没有什么区别。

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

清风无影 2024-07-24 00:45:43

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文