How to use INFORMATION_SCHEMA.COLUMNS In Databases

Another method involves updating the column name directly in the INFORMATION_SCHEMA.COLUMNS system table.

-- Update the column name in the INFORMATION_SCHEMA.COLUMNS table
UPDATE INFORMATION_SCHEMA.COLUMNS
SET COLUMN_NAME = 'name'
WHERE TABLE_NAME = 'employees' AND COLUMN_NAME = 'emp_name';

-- Describe the structure of the 'employees' table
DESCRIBE employees;

Output:

Output

Explanation: The emp_name column has been successfully renamed to name.

How to Rename Column in MariaDB

In database management, maintaining an efficient and well-organized schema is important. One common task is to rename columns which can enhance clarity, attach to naming conventions or accommodate structural changes.

In this article, we’ll learn about various methods along with examples such as ALTER TABLE statement with CHANGE COLUMN or RENAME COLUMN and INFORMATION_SCHEMA.COLUMNS system table which helps in renaming the columns easily.

Similar Reads

How to Rename Column Name?

Renaming columns in a database table is a routine operation performed during database maintenance or schema evolution. While the process may look simple, it is important to understand the various methods available to ensure a smooth transition without compromising data integrity....

1. Using ALTER TABLE with Change Column

The ALTER TABLE statement in MariaDB allows us to modify an existing table’s structure including renaming columns. The syntax for renaming a column using CHANGE COLUMN is as follows:...

2. Using ALTER TABLE with Rename Column

We can also change the column name with the help of ALTER TABLE with Rename Column Statement. Let’s see the below example....

3. Using INFORMATION_SCHEMA.COLUMNS

Another method involves updating the column name directly in the INFORMATION_SCHEMA.COLUMNS system table....

4. Using a Temporary Table

Creating a temporary table and transferring data with the desired column name is another approach....

Conclusion

Renaming columns in MariaDB can be achieved through various methods each method offering its own advantages and considerations. Whether you prefer the simplicity of the ALTER TABLE statement or the direct update using INFORMATION_SCHEMA.COLUMNS or the flexibility of temporary tables, it is important to choose the method that best fits your workflow while ensuring data integrity and minimal loss to your database operations....