MySQL non-primary key self-growth

Source: Internet
Author: User

MySQL is not only the primary key to self-growth, but the column set as the key can be set to self-growth.

As follows:
1234 CREATE TABLE t1 (    id INT,    col1 INT auto_increment NOT NULL);
The result is as follows: If you set the Col1 column as the key, you can create a self-increment.
12345 CREATE TABLE t1 (    id INT,    col1 INT auto_increment NOT NULL,    key(col1));
The results are as follows: If we set the ID as the primary key, we can still create the success.
12345 CREATE TABLE t2 (    id INT PRIMARY KEY,    col1 INT auto_increment NOT NULL,    key(col1));
The results are as follows: so the self-increment column must be a key , but not necessarily a primary key. But can a table have multiple self-increment columns? A: A table can only have one self-increment column .
12345 CREATE TABLE t3 (    id INT PRIMARY KEY auto_increment,    col1 INT auto_increment NOT NULL,    key(col1));
The results are as follows:

The conclusion is that each table can only be set to a field that is self-growing, which can be either a primary key or a primary key, or it must be set to a key if it is not a primary key.

In fact, the primary key (primary key) is also one of the keys, key also includes the foreign key (foreign key), unique key, etc., about key discussion can see the post http://www.cnblogs.com/tanzq/p /9064511.html

MySQL non-primary key self-growth

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.