
- 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
What is the benefit of zerofill in MySQL?
ZEROFILL pads the displayed value of the field with zeros up to the display width set in the column definition. Let us understand the role of zero fill in MySQL using an example. Creating a table with two columns, one has zerofill and the second one does not. The query to create a table.
mysql> create table ZeroFillDemo -> ( -> First int(18) zerofill, -> Second int(18) -> ); Query OK, 0 rows affected (0.63 sec)
We can insert records in the table with the help of INSERT command. The query is as follows.
mysql> insert into ZeroFillDemo values(1,1); Query OK, 1 row affected (0.13 sec) mysql> insert into ZeroFillDemo values(12,12); Query OK, 1 row affected (0.15 sec) mysql> insert into ZeroFillDemo values(123,123); Query OK, 1 row affected (0.10 sec) mysql> insert into ZeroFillDemo values(123456789,123456789); Query OK, 1 row affected (0.20 sec)
Now, we can check the benefits of zerofill column with the help of select command.
The query is as follows.
mysql> select *from ZeroFillDemo;
The following is the output.
+--------------------+-----------+ | First | Second | +--------------------+-----------+ | 000000000000000001 | 1 | | 000000000000000012 | 12 | | 000000000000000123 | 123 | | 000000000123456789 | 123456789 | +--------------------+-----------+ 4 rows in set (0.00 sec)
Look at the sample output,zero is filled at the beginning.
- Related Articles
- What is the usage of zerofill in a MySQL field?
- MySQL BigInt zerofill vs int zerofill?
- What is the benefit of MySQL ‘IS NULL’ and ‘IS NOT NULL’?
- What is the usage of ZEROFILL for INT datatype?
- What is the benefit of using MySQL SUM() function with GROUP BY clause?
- What is the Benefit of Using Digital Data?
- What is Marginal Benefit?
- Set custom Auto Increment with ZEROFILL in MySQL
- What is Not a Benefit of Google Analytics Remarketing?
- What is Accidental Death Benefit and what are its types?
- What is ball tempering and how does it benefit a bowler in the game?
- What Industry Will Benefit the Most from IoT Applications?
- Impact and Benefit of Change Management
- The Maternity Benefit Act: An Overview
- How Blockchain technology can benefit the Internet of things?

Advertisements