Rename a Column Name in SQL
In this Article you will learn about
How To Rename a Column Name in SQL?
Renaming a column in a table in SQL is a simple task that can be accomplished using the ALTER TABLE statement and the RENAME COLUMN clause.
Here’s an example of how to use these statements to rename a column in a table called customers:
CREATE TABLE customers ( customer_id INTEGER PRIMARY KEY, customer_name VARCHAR(255), phone_number VARCHAR(255), address VARCHAR(255) );
This code creates a table called customers with four columns: customer_id, customer_name, phone_number, and address
The customers table will have the following structure:
customer_id | customer_name | phone_number | address |
Query To Rename the Column name is :
ALTER TABLE customers RENAME COLUMN customer_name TO full_name;
Now it renames the customer_name column to full_name.
After running the above code,
the customers table After rename will have the following structure :
customer_id | full_name | phone_number | address |
Note that the syntax for renaming a column may vary slightly depending on the database you are using. Consult the documentation for the specific database you are using for more information.