

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display auto increment user id sequence number to begin from 001 in MySQL?
For this, use ZEROFILL and alter the table to begin from the same sequence −
alter table yourTableName change yourColumnName yourColumnName int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY;
To understand the above syntax, let us first create a table −
mysql> create table DemoTable1958 ( UserId int, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Here is the query to alter generated sequence number to begin from 001:
mysql> alter table DemoTable1958 change UserId UserId int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the table description:
mysql> desc DemoTable1958;
This will produce the following output −
+----------+--------------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------------------+------+-----+---------+----------------+ | UserId | int(3) unsigned zerofill | NO | PRI | NULL | auto_increment | | UserName | varchar(20) | YES | | NULL | | +----------+--------------------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1958(UserName) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1958(UserName) values('David'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1958;
This will produce the following output −
+--------+----------+ | UserId | UserName | +--------+----------+ | 001 | Chris | | 002 | David | +--------+----------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Auto increment in MongoDB to store sequence of Unique User ID?
- How do I begin auto increment from a specific point in MySQL?
- How can I set my auto-increment value to begin from 1 in MySQL?
- How to get the next auto-increment id in MySQL?
- How to change auto increment number in MySQL?
- How to handle fragmentation of auto increment ID column in MySQL?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- How to change auto increment number in the beginning in MySQL?
- Passing NULL to MySQL for auto increment?
- Change the Auto Increment counter in MySQL?
- Set custom Auto Increment with ZEROFILL in MySQL
- How to make MySQL table primary key auto increment?
- How to auto increment with 1 after deleting data from a MySQL table?
- Extract the user ID from the username only in MySQL?
- How to set initial value and auto increment in MySQL?
Advertisements