Home > Database > Mysql Tutorial > primary key increment in mysql

primary key increment in mysql

黄舟
Release: 2016-12-28 17:50:24
Original
1312 people have browsed it

CREATE TABLE customers
(
cust_id int NOT NULL AUTO_INCREMENT,
cust_name char(50) NOT NULL ,
PRIMARY KEY (cust_id)
) ENGINE=InnoDB;
Copy after login

When executed for the first time:

insert into customers values(1,'aaa');
Copy after login

When executed for the second time:

insert into customers values(null,'bbb');
Copy after login

The primary key of the second record is 2



Insert the third record:

insert into customers2(cust_name) values('ccc');
Copy after login

When using it, it is best to use the third record to prevent the table from increasing later. When, the sql statement that inserts data reports an error.



Insert the fourth and fifth records:

insert into customers2 (cust_name) values ('ee'),('ff');
Copy after login

When inserting more than 2 statements together, separate them with commas.



The meaning of ENGINE=InnoDB:

The storage engine is innodb. nnoDB is the first data storage engine on MySQL to provide foreign key constraints. In addition to providing transaction processing, InnoDB also supports row locks, providing the same consistent lock-free reading as Oracle, which can increase the number of concurrent reading users and Improves performance without increasing the number of locks. InnoDB is designed to maximize performance when processing large volumes of data, and its CPU utilization is the most efficient of any other disk-based relational database engine.

InnoDB is a complete database system placed in the MySQL backend. InnoDB has its own buffer pool that can buffer data and indexes. InnoDB also stores data and indexes in table spaces, which may contain several files. , which is completely different from the MyISAM table. In MyISAM, the table is stored in a separate file. The size of the InnoDB table is only limited by the size of the operating system file, which is generally 2GB.

The above is the content of primary key increment in mysql. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template