
- 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 a custom value for AUTO_INCREMENT while creating a table and use ZEROFILL. What will happen now when nothing is inserted while using INSERT statement?
We will see an example and create a table wherein we have set StudentId column as AUTO_INCREMENT = 100 and used ZEROFILL as well −
mysql> create table DemoTable ( StudentId int(7) ZEROFILL NOT NULL AUTO_INCREMENT, PRIMARY KEY(StudentId) )AUTO_INCREMENT=100; Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command. Now, when nothing is inserted, the value would begin from 101 (auto_increment) and rest of the values in the left would be filled with 0 since we have set ZEROFILL while creating the table above −
mysql> insert into DemoTable values(); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+ | StudentId | +-----------+ | 0000100 | | 0000101 | | 0000102 | | 0000103 | +-----------+ 4 rows in set (0.00 sec)
- Related Articles
- Set custom Auto Increment with ZEROFILL in MySQL
- Truncate a MySQL table and then set a custom value to auto increment
- Error occurs when table name “references” is set while creating a table
- Set auto increment initial value for MySQL table using ALTER command
- Can we use {} while creating a MySQL table?
- Set DEFAULT values for columns while creating a table in MySQL
- What is MySQL GENERATED COLUMN and how to use it while creating a table?
- Set AUTO_INCREMENT in a table while creating it in MySQL?
- While creating a MySQL table use the reserved keyword ‘Key’
- Is there a need to insert auto_increment column values in MySQL while using INSERT statement?
- Set special characters for password while creating a new MySQL user?
- Set options while creating a MySQL table. Display the same options as well
- What is the use of DEFAULT constraint? How can it be applied to a column while creating a table?
- What is a common debugging workflow while creating a model using Keras in Python?
- How to set auto-increment to an existing column in a table using JDBC API?

Advertisements