Errors Caused by Data Types of MySQL primary keys (automatically added)

Source: Internet
Author: User
Some time ago, when I made a website, I used a MySQL database and EMS MySQL manager to create and manage databases. One of the tables has an auto-incrementing primary key ID, because the default auto-increment Data Type of the table created by EMS MySQL manager is tinyint, this problem was not noticed at the beginning. Today, I found that I cannot insert data into the database. The error is that 127 of the records in the ID column already exist! After checking the database, it exists, but the ID column is obviously auto-incrementing. I didn't specify the value of the ID column in the insert statement. Why does this problem occur?

After checking the database, I found that the data type of the ID column is tinyint, and then I thought how could it be such a special number as 127 (128-1? Later I thought whether tinyint can only represent-127 ~ What about the number between 127? As a result, I changed the data type to integer!

It seems that it is important to select the correct database data type.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.