本文介绍了术语“元组"是什么意思?在关系数据库中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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)

...当然,假设x,y和z都是整数.另请注意,没有重复"元组之类的东西.因此,上述条件不仅相等,而且是同一件事.最后,元组只能包含已知值(因此,不能为null).

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

**是一组带名称的已知或未知值的有序集合(尽管可以将其省略).因此,以下比较在SQL中返回false:

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)

请注意,尽管有一些方法可以伪造"它.例如,考虑以下INSERT语句:

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

INSERT INTO point VALUES (1, 2, 3)

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

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)

或者这个:

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)

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

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

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

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.

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

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.

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

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

更新:我在博客文章此处.

这篇关于术语“元组"是什么意思?在关系数据库中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:05