I'm learning MySQL. I came across some multiple-choice questions. If I doubted what the answer was or was not convinced it's correct I started searching google, * and the mysql site. However for some I still couldn't confirm what the correct answer was.
我正在学习MySQL。我遇到了一些多项选择题。如果我怀疑答案是什么或者不相信它是正确的我开始搜索谷歌,*和mysql网站。但对于一些人,我仍然无法确认正确答案是什么。
Question: all of the following statements are true about a unique index except which one?
A. it must be unique for all columns of a table
B. it should not be explicitly defined for tables
C. It must be created only for columns having PRIMARY KEY or UNIQUE constraints.
D. It cannot be created by itself
E. It cannot be ensured that the combination of all values contained in the index are unique
问题:以下所有关于唯一索引的陈述都是正确的,除了哪一个?答:对于表B的所有列,它必须是唯一的。不应为表C显式定义它。必须仅为具有PRIMARY KEY或UNIQUE约束的列创建它。 D.它不能自己创建E.无法确保索引中包含的所有值的组合是唯一的
Proposed answer: E.
建议答案:E。
My thoughts:
A. I really have no clue what they mean by it. But in this question it should be a correct statement. Can someone make this clear?
B. defined for tables? a unique index is on a table column. And by default non unique values are possible so it should be explicitly defined
C. Looks correct. Primary key is unique as well so therefor an index should be built by MySQL (however not explicitly)
D. wut? another answer that doesn't make any sense to me (am I stupid? :S)
E. Combination of values? No then it can't be ensured that these combinations of the values of a column are unique. If it is combinations of the different columns that might be combined in a primary key: then it can be ensured otherwise there is no use for a UNIQUE index.
答:我真的不知道它们的意思。但在这个问题上,它应该是一个正确的陈述。有人能说清楚吗? B.为表定义?表列上有唯一索引。默认情况下,非唯一值是可能的,因此应明确定义C.看起来正确。主键也是唯一的,因此应该由MySQL构建索引(但不是明确的)D.但是?另一个对我没有任何意义的答案(我是愚蠢的吗?:S)E。价值观的结合?否则无法确保列值的这些组合是唯一的。如果它是可能在主键中组合的不同列的组合:则可以确保不使用UNIQUE索引。
Mostly I'm able to have a preferred answer when in doubt, however here I have no clue:s
大多数情况下,当有疑问时我能得到一个首选答案,但是在这里我没有任何线索:s
This one is really driving me nuts:s Is this just a language barrier or ...
这个真的让我疯狂:这只是语言障碍还是......
If you have any remark about this question/answer or for any of my remarks I'm happy to hear it!
如果您对这个问题/答案有任何评论,或者对于我的任何评论,我很高兴听到它!
1 个解决方案
#1
0
These answers do not makes sense:
这些答案没有意义:
A. it must be unique for all columns of a table
答:对于表的所有列,它必须是唯一的
A unique index is generally defined on a subset of columns of a table. A given index would only apply to all columns if it were defined that way. Hence, this is false.
通常在表的列的子集上定义唯一索引。如果以这种方式定义,则给定索引仅适用于所有列。因此,这是错误的。
B. it should not be explicitly defined for tables
B.不应为表明确定义
Why would the construct exist if it shouldn't be used? Unique indexes are quite useful. One could argue that it is not defined on "tables" but on "columns in tables", but that seems too nuanced for this question.
如果不应该使用构造,为什么会存在?唯一索引非常有用。有人可能会说它没有在“表格”上定义,而是在“表格中的列”中定义,但这对于这个问题来说似乎太微妙了。
C. It must be created only for columns having PRIMARY KEY or UNIQUE constraints.
C.必须仅为具有PRIMARY KEY或UNIQUE约束的列创建它。
This comes close to being true. You could argue that creating a unique index is equivalent to creating a unique constraint. However, they are different syntactic constructs for doing the same thing. Furthermore, you wouldn't create a unique index for a column with a unique constraint, because the database does it for you.
这接近成真。您可以争辩说,创建唯一索引等同于创建唯一约束。但是,它们是用于执行相同操作的不同语法结构。此外,您不会为具有唯一约束的列创建唯一索引,因为数据库会为您执行此操作。
D. It cannot be created by itself
D.它不能自己创造
I don't know what this is supposed to mean. In a sense, it cannot be created "by itself" because it needs a table to be defined on.
我不知道这是什么意思。从某种意义上说,它不能“自己”创建,因为它需要定义一个表。
E. It cannot be ensured that the combination of all values contained in the index are unique
E.无法确保索引中包含的所有值的组合是唯一的
This is true, because NULL values are allowed to be duplicated:
这是事实,因为允许重复NULL值:
A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, a UNIQUE index permits multiple NULL values for columns that can contain NULL.][1]
I would read that only (e) is unambiguously true. Options (c) and (d) come close, depending on the interpretation. Options (a) and (b) seem false to my reading.
我会读到只有(e)是明确无误的。选项(c)和(d)接近,取决于解释。选项(a)和(b)对我的阅读似乎是错误的。
You may want to look somewhere else for such questions.
您可能希望在其他地方寻找此类问题。
#1
0
These answers do not makes sense:
这些答案没有意义:
A. it must be unique for all columns of a table
答:对于表的所有列,它必须是唯一的
A unique index is generally defined on a subset of columns of a table. A given index would only apply to all columns if it were defined that way. Hence, this is false.
通常在表的列的子集上定义唯一索引。如果以这种方式定义,则给定索引仅适用于所有列。因此,这是错误的。
B. it should not be explicitly defined for tables
B.不应为表明确定义
Why would the construct exist if it shouldn't be used? Unique indexes are quite useful. One could argue that it is not defined on "tables" but on "columns in tables", but that seems too nuanced for this question.
如果不应该使用构造,为什么会存在?唯一索引非常有用。有人可能会说它没有在“表格”上定义,而是在“表格中的列”中定义,但这对于这个问题来说似乎太微妙了。
C. It must be created only for columns having PRIMARY KEY or UNIQUE constraints.
C.必须仅为具有PRIMARY KEY或UNIQUE约束的列创建它。
This comes close to being true. You could argue that creating a unique index is equivalent to creating a unique constraint. However, they are different syntactic constructs for doing the same thing. Furthermore, you wouldn't create a unique index for a column with a unique constraint, because the database does it for you.
这接近成真。您可以争辩说,创建唯一索引等同于创建唯一约束。但是,它们是用于执行相同操作的不同语法结构。此外,您不会为具有唯一约束的列创建唯一索引,因为数据库会为您执行此操作。
D. It cannot be created by itself
D.它不能自己创造
I don't know what this is supposed to mean. In a sense, it cannot be created "by itself" because it needs a table to be defined on.
我不知道这是什么意思。从某种意义上说,它不能“自己”创建,因为它需要定义一个表。
E. It cannot be ensured that the combination of all values contained in the index are unique
E.无法确保索引中包含的所有值的组合是唯一的
This is true, because NULL values are allowed to be duplicated:
这是事实,因为允许重复NULL值:
A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, a UNIQUE index permits multiple NULL values for columns that can contain NULL.][1]
I would read that only (e) is unambiguously true. Options (c) and (d) come close, depending on the interpretation. Options (a) and (b) seem false to my reading.
我会读到只有(e)是明确无误的。选项(c)和(d)接近,取决于解释。选项(a)和(b)对我的阅读似乎是错误的。
You may want to look somewhere else for such questions.
您可能希望在其他地方寻找此类问题。