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:
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.