
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to change auto increment number in the beginning in MySQL?
The auto_increment is a default property that automatically increments the newly added record by 1. The auto_increment can be changed from the beginning as well. The procedure for that is given below −
First, a table is created.
mysql> CREATE table DemoAuto -> ( -> id int auto_increment, -> name varchar(100), -> primary key(id) -> ); Query OK, 0 rows affected (0.47 sec)
After that the alter table command is used to change the starting number of auto_incremnt which starts from 1 by default. The starting value is changed to 100.
mysql> alter table DemoAuto auto_increment = 100; Query OK, 0 rows affected (0.24 sec) Records: 0 Duplicates: 0 Warnings: 0
Then some records are inserted into the table.This is given as follows −
mysql> INSERT into DemoAuto(name) values('John'); Query OK, 1 row affected (0.10 sec) mysql> INSERT into DemoAuto(name) values('Smith'); Query OK, 1 row affected (0.13 sec) mysql> INSERT into DemoAuto(name) values('Bob'); Query OK, 1 row affected (0.22 sec)
The select statement is used to obtain the table values as output. This is given below −
mysql> SELECT * from DemoAuto;
The following is the output obtained −
+-----+-------+ | id | name | +-----+-------+ | 100 | John | | 101 | Smith | | 102 | Bob | +-----+-------+ 3 rows in set (0.00 sec)
In the above output, the record id starts from 100.
- Related Articles
- How to change auto increment number in MySQL?
- Change the Auto Increment counter in MySQL?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- How to get the next auto-increment id in MySQL?
- How to set initial value and auto increment in MySQL?
- Display auto increment user id sequence number to begin from 001 in MySQL?
- How to handle fragmentation of auto increment ID column in MySQL?
- How to make MySQL table primary key auto increment?
- Passing NULL to MySQL for auto increment?
- How to auto-increment value of tables to lower value in MySQL?
- How to add auto-increment to column in MySQL database using PhpMyAdmin?
- Set custom Auto Increment with ZEROFILL in MySQL
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- How to create a table with auto-increment column in MySQL using JDBC?
- Changing the current count of an Auto Increment value in MySQL?

Advertisements