
- 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
How to convert all the records in a MySQL table from uppercase to lowercase?
Convert all the records in a MySQL table from uppercase to lowercase using UPDATE command along with LOWER() method.
Let us first create a table −
mysql> create table DemoTable ( Id varchar(100), StudentFirstName varchar(20), StudentLastName varchar(20), StudentCountryName varchar(10) ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('STU-101','John','Smith','US'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('STU-102','John','Doe','UK'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU-103','David','Miller','AUS'); Query OK, 1 row affected (0.19 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------+------------------+-----------------+--------------------+ | Id | StudentFirstName | StudentLastName | StudentCountryName | +---------+------------------+-----------------+--------------------+ | STU-101 | John | Smith | US | | STU-102 | John | Doe | UK | | STU-103 | David | Miller | AUS | +---------+------------------+-----------------+--------------------+ 3 rows in set (0.00 sec)
Here is the query to change the case on every field in a MySQL table in a single call.
mysql> update DemoTable set Id=lower(Id), StudentFirstName=lower(StudentFirstName), StudentLastName=lower(StudentLastName), StudentCountryName=lower(StudentCountryName); Query OK, 3 rows affected (0.22 sec) Rows matched: 3 Changed: 3 Warnings: 0
Display all records from the table using select statement to check the changes done in the above query −
mysql> select *from DemoTable;
This will produce the following output −
+---------+------------------+-----------------+--------------------+ | Id | StudentFirstName | StudentLastName | StudentCountryName | +---------+------------------+-----------------+--------------------+ | stu-101 | john | smith | us | | stu-102 | john | doe | uk | | stu-103 | david | miller | aus | +---------+------------------+-----------------+--------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to convert all uppercase letters in string to lowercase in Python?
- How to find all uppercase strings in a MySQL table?
- Convert All Lowercase Text of a File into Uppercase in Java?
- How to convert lowercase letters in string to uppercase in Python?
- Convert string to lowercase or uppercase in Arduino
- Delete all the records from a MySQL table?
- Java program to convert a string to lowercase and uppercase.
- Delete all records from a table in MySQL?
- How to delete all the duplicate records in a MySQL table?
- How to convert the content of the file into uppercase or lowercase?
- Making a Java String All Uppercase or All Lowercase.
- How can we fetch all the records from a particular MySQL table?
- A single MySQL query to insert records (not all) in the second table from the first table
- How to select all the records except a row with certain id from a MySQL table?
- Write a C program to convert uppercase to lowercase letters without using string convert function

Advertisements