MySQL表需要ID吗? [英] Do MySQL tables need an ID?

查看:302
本文介绍了MySQL表需要ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
每个表都应该有一个主键吗?

Possible Duplicate:
Should each and every table have a primary key?

如果您从不在任何地方引用ID,是否有必要添加ID?表需要ID或主键吗?

If you never refer to the ID anywhere is it necessary to include one? Does a table need an ID or primary key?

推荐答案

不,您不需要使表在MySQL中正常工作.就是说,主键允许唯一值引用另一个表或使用该表的任何代码中的表中的一行.

No you do not need a primary key to make a table work in MySQL. That said, a primary key allows for a unique value to refer to a row in a table from another table, or in any code using the table.

您确实需要一个主键来使表在MySQL中正常运行.索引(主键是其中的索引)使MySQL可以搜索表的小型,高度优化的子集,以处理关系和搜索.通常,在WHERE子句中使用或用于将两个表链接在一起的任何字段都应建立索引.

You do need a primary key to make a table work well in MySQL though. Indexes (which the primary key is one of) allow MySQL to search through small, highly optimized subsets of the table to process relationships and searches. In general, any fields that you use in a WHERE clause or use to link two tables together should be indexed.

这篇关于MySQL表需要ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆