
- 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
Set custom Auto Increment with ZEROFILL in MySQL
Let us first create a table. Here. We have set UserId column with ZEROFILL and AUTO_INCREMENT
mysql> create table DemoTable1831 ( UserId int(7) zerofill auto_increment, PRIMARY KEY(UserId) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1831 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1831 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1831 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1831 values(); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1831;
This will produce the following output. All the values have zerofill for UserId field width 7
+---------+ | UserId | +---------+ | 0000101 | | 0000102 | | 0000103 | | 0000104 | +---------+ 4 rows in set (0.00 sec)
- Related Articles
- Truncate a MySQL table and then set a custom value to auto increment
- How to set initial value and auto increment in MySQL?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- Set auto increment initial value for MySQL table using ALTER command
- Two columns as primary key with auto-increment in MySQL?
- What if I forgot to set Auto Increment? Can I set it later in MySQL?
- Change the Auto Increment counter in MySQL?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- How can I set my auto-increment value to begin from 1 in MySQL?
- How to change auto increment number in MySQL?
- Set the MySQL primary keys auto increment to be unlimited (or incredibly huge)?
- Passing NULL to MySQL for auto increment?
- How to create a table with auto-increment column in MySQL using JDBC?
- MySQL BigInt zerofill vs int zerofill?
- Increment column value ‘ADD’ with MySQL SET clause

Advertisements