Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql self-increasing column

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Mysql creates a table with self-increasing columns

Create table inc (id int (10) not null auto_increment,name varchar (20), primary key (id))

Note:

Auto-increment column must be key

There are no quotation marks in the front id, and there can be no quotation marks when the back is set to key

2. Use self-incrementing column

Mysql > insert into inc values (id,'leo')

Query OK, 1 row affected (0.00 sec)

Mysql > select * from inc

+-+ +

| | id | name |

+-+ +

| | 1 | leo |

+-+ +

1 row in set (0.00 sec)

Mysql > insert into inc values (id,'dem')

Query OK, 1 row affected (0.00 sec)

Mysql > select * from inc

+-+ +

| | id | name |

+-+ +

| | 1 | leo |

| | 2 | dem |

+-+ +

2 rows in set (0.00 sec)

You can see that the self-increment column starts from 1 by default.

3. Set self-increment column

If you do not want the increment column to start at 1, you can use the following statement to modify the starting value of the increment

Alter table inc auto_increment=100

Mysql > insert into inc values (id,'jack')

Query OK, 1 row affected (0.01sec)

Mysql > select * from inc

+-+ +

| | id | name |

+-+ +

| | 1 | leo |

| | 2 | dem |

| | 100 | jack |

+-+ +

3 rows in set (0.00 sec)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report