How to change column names in mysql?

Member

by lottie , in category: MySQL , a year ago

How to change column names in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , a year ago

@lottie 

To change column names in MySQL, you can use the ALTER TABLE statement along with the CHANGE keyword. Here's the syntax:

1
ALTER TABLE table_name CHANGE current_column_name new_column_name column_definition;


Example:


Let's say we have a table called employees with the following structure:

1
2
3
4
5
CREATE TABLE employees (
  id INT PRIMARY KEY,
  name VARCHAR(50),
  age INT
);


Now, let's change the name of the 'age' column to 'years_old':

1
ALTER TABLE employees CHANGE age years_old INT;


This will change the column name from 'age' to 'years_old' while keeping the data type of the column as INT.

Related Threads:

How to copy column names from teradata?
How to select columns on the basis of column names in oracle?
How to properly compare bigint column in mysql 5.7?
How to sum array column in mysql?
How to select previous column value in mysql?
How to get index of no zero column in mysql?