Mysql defines a primary key as an automatically increasing Identifier type.

Source: Internet
Author: User
Mysql defines the primary key as the automatic growth Identifier type. in this article, we will share how mysql defines the primary key as the automatic growth Identifier type.

1. define the primary key as the automatic growth Identifier type in mysql. if the primary key of the table is set to the auto_increment type, the database automatically assigns a value to the primary key. For example:

Create table MERS (id int auto_increment primary key notnull, name varchar (15); insert into MERS (name) values ("name1"), ("name2 ");

Once the id is set to auto_increment type, mysql database automatically assigns a value to the primary key in ascending mode.

In MS SQLServer, if the table's primary key is set to the identity type, the database automatically assigns a value to the primary key. For example:

Create table MERS (id int identity (1, 1) primary key notnull, name varchar (15); -- www. jbxue. cominsert into MERS (name) values ("name1"), ("name2"); select id from customers;

The query result is the same as that of mysql. It can be seen that, once the id is set to the identity type, the MSSQLServer database automatically assigns a value to the primary key in ascending mode.

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.