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

Whether the MySQL unique key is case-sensitive

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "whether the MySQL unique key is case-sensitive". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "whether the MySQL unique key is case-sensitive".

Create a student table student, which contains two fields: id and name. Id is set to self-increment and name is set to unique.

Add a student Tom. If you add it successfully, you can query the

Add another student whose name is set to tom. Failed to add. Hint: tom is repeated in the student.name key.

Since it is said that tom already exists, it can be queried by using tom as a condition, and the field value in the result is Tom.

In view of this, it seems that mysql is not case-sensitive when comparing fields, so it should be a case-unified comparison.

Experimental SQL

Mysql > CREATE TABLE `student` (- > `id` int (11) NOT NULL AUTO_INCREMENT,-> `name` varchar 'DEFAULT NULL COMMENT' name',-> PRIMARY KEY (`id`),-> UNIQUE KEY `name` (`name`)-> ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=' Student form'; Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql > insert into student (name) values ('Tom'); Query OK, 1 row affected (0.00 sec) mysql > select * from student +-+-+ | id | name | +-+-+ | 1 | Tom | +-+-+ 1 row in set (0.00 sec) mysql > insert into student (name) values ('tom'); ERROR 1062 (23000): Duplicate entry' tom' for key 'student.name'mysql > select * from student where name='tom' +-+-+ | id | name | +-+-+ | 1 | Tom | +-+-+ 1 row in set (0.00 sec) Thank you for your reading. The above is the content of "whether the unique key of MySQL is case-sensitive". After studying this article, I believe you have a deeper understanding of whether the unique key of MySQL is case-sensitive. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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: 0

*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

Development

Wechat

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

12
Report