Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between unique and primary key in mysql

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the difference between unique and primary key in mysql". the explanation in this article is simple and clear, easy to learn and understand. please follow the idea of Xiaobian and go deep into it slowly to study and learn "what is the difference between unique and primary key in mysql" together!

Unique constraints ensure that there are no duplicate values in a column, and unique and primary key constraints both provide guarantees for the uniqueness of a column of values.

Unique can appear multiple times in each table, while primary key can only appear one time.

examples

mysql> create table user (name varchar(255),constraint name_un unique(name));Query OK, 0 rows affected (0.07 sec) mysql> insert user values("");Query OK, 1 row affected (0.02 sec) mysql> insert user values("zhang san");ERROR 1062 (23000): Duplicate entry 'zhang san' for key 'user.name_un'mysql> alter table user drop index name_un; Query OK, 0 rows affected (0.03 sec)Records: 0 Duplicates: 0 Warnings: 0 mysql> insert user values("ZHANG SAN"); Query OK, 1 row affected (0.02 sec) Thank you for reading, the above is "what is the difference between unique and primary key in mysql" content, after the study of this article, I believe that we have a deeper understanding of what is the difference between unique and primary key in mysql, the specific use of the situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 219

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report