开发者

mysql table: index vs primary

i am a newbie and am a bit concerned about the effici开发者_运维百科ency of mysql table. what are the pros and cons of making a field in mysql table as

  1. index
  2. primary

what is the followed practise in deciding on the attributes of a field in a mysql table? please share your insights, thanks.


You can only have one primary key in a table. It should be a column that uniquely identifies each record in your table. A primary key is not a requirement; for example, you may have a table to implement a many-to-many relationship and a unique id is not needed for those records.

Indexes should be used whenever you must query a table and specify some criteria to filter records based on a column's value (e.g. WHERE clause). There is a lot to learn about indexes, for example: when to create an index on one column vs. multiple columns in the same index. Read the documentation on the MySQL website about indexes to learn more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜