- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
- What is the usage of zerofill in a MySQL field?
- What is Marginal Benefit?
- MySQL BigInt zerofill vs int zerofill?
- 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 MySQL ‘IS NULL’ and ‘IS NOT NULL’?
- What is Accidental Death Benefit and what are its types?
- Set custom Auto Increment with ZEROFILL in MySQL
- What is ball tempering and how does it benefit a bowler in the game?
- How Blockchain technology can benefit the Internet of things?
- What is the use of NCHAR in MySQL?
- What is the equivalent of EXCEPT in MySQL?
- What is the use of RLIKE operator in MySQL?
- What is the limit of auto_increment (integer) in MySQL?
- What is the use of FIND_IN_SET () function in MySQL?