MySQL can only have one auto growth field per table. This auto growth field can be used as a primary key or a non primary key. However, please note that when you use an auto growth field as a non primary key, you must add a unique index to it, otherwise the system will report an error. For example:
1. Set the auto grow field as the primary key.
create table t1 (id int auto_ increment Primary key,sid int);
2. Set the auto grow field to a non primary key. Note that the unique key must be added explicitly.
create table t2 (sid int primary key,id int auto_ increment Unique);
3. Set the auto growth field to a non primary key. If no unique index is added, an error will be reported * *, as shown in the following statement
create table t3 (sid int primary key,id int auto_ increment)。
MySQL is a relational database management system, developed by MySQL AB company of Sweden, which is a product of Oracle at present. MySQL is one of the most popular relational database management systems. In web application, MySQL is the best RDBMS (relational database management system) application software. MySQL is a kind of relational database management system. Relational database stores data in different tables instead of putting all data in a large warehouse, which increases the speed and flexibility. The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software adopts dual authorization policy, which is divided into community version and commercial version. Because of its small size, fast speed, low total cost of ownership, especially the open source, MySQL is generally chosen as the website database for the development of small and medium-sized websites. Because of the excellent performance of its community version, it can form a good development environment with PHP and Apache
come from: https://zhidao.baidu.com/question/621026495899595372.html
Read More:
- Modification method of starting value of MySQL auto increment ID
- Txt import MySQL: error 1062 (23000): duplicate entry ‘0’ for key ‘primary’
- The solution of duplicate entry ‘for key’ primary ‘when inserting data in MySQL
- Duplicate entry ‘787192513’ for key ‘primary’
- MySQL creates tables and sets auto increment of primary keys
- Solution of duplicate entry ‘value’ for key ‘field name’ in MySQL
- sqoop-import ERROR tool.ImportTool: Import failed: No primary key could be found for table user_info
- 1072 – Key column ‘xxx_id’ doesn’t exist in table
- A simple method of generating secret key by GIT and configuring SSH public key
- The problem that headers [‘content-type ‘] does not work is set in the Axios get method request interface
- MySQL error set: failed to start mysql.service : Unit mysql.service is masked.
- MySql 8.x java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
- MySQL failed to add foreign key: SQL 1452 cannot add or update a child row:a foreign key constraint fails
- Using code to create control objects, set the event listening method does not execute
- There is a solution to the problem: severity = corrected, type = physical layer, id = 00e5 or id = 00e8 (receiver ID) under Ubuntu
- MySQL failed to add foreign key error 1452
- Export and import method of MySQL under Linux
- MySQL modify character set
- MySQL:Foreign key fails with error Error Code: 1452.
- MySql ERROR CODE:1215 Cannot add the foreign key constraint