Suppose we have a data table/entity in MySQL DB. As we know that we can retrieve data from a table using Primary key and Self-Created key. Now my question is which approach is faster to retrieve data? Using primary key or self-created key? Then ( if the answer is primary key or self-created key ) why this data manipulation will be faster?
假设我们在MySQL DB中有一个数据表/实体。我们知道我们可以使用Primary key和Self-Created键从表中检索数据。现在我的问题是哪种方法可以更快地检索数据?使用主键还是自创键?然后(如果答案是主键或自创键)为什么这个数据操作会更快?
1 个解决方案
#1
-1
If you can use a composite key it will be faster than primary key.
如果您可以使用复合键,它将比主键快。
A composite key, in the context of relational databases, is a combination of two or more columns in a table that can be used to uniquely identify each row in the table.
在关系数据库的上下文中,组合键是表中两个或多个列的组合,可用于唯一标识表中的每一行。
It defines your data. It may be an identity column, it may be a varchar column or a datetime column or an integer column, or it may be a combination of multiple columns. When you define more than one column as your primary key on a table, it is called a composite primary key.
它定义了您的数据。它可以是标识列,可以是varchar列,也可以是日期时间列或整数列,也可以是多列的组合。在表上定义多个列作为主键时,它称为复合主键。
#1
-1
If you can use a composite key it will be faster than primary key.
如果您可以使用复合键,它将比主键快。
A composite key, in the context of relational databases, is a combination of two or more columns in a table that can be used to uniquely identify each row in the table.
在关系数据库的上下文中,组合键是表中两个或多个列的组合,可用于唯一标识表中的每一行。
It defines your data. It may be an identity column, it may be a varchar column or a datetime column or an integer column, or it may be a combination of multiple columns. When you define more than one column as your primary key on a table, it is called a composite primary key.
它定义了您的数据。它可以是标识列,可以是varchar列,也可以是日期时间列或整数列,也可以是多列的组合。在表上定义多个列作为主键时,它称为复合主键。