Menu
Course Lessons
5 Resume Writing Myths That You Need to Stop Following Now!
How to Perform Pivot in SQL?
Nested Queries in SQL - Query In Query
How to Drop a Table in PostgreSQL?
Working of Correlated SubQueries in SQL
Joins and Its Types in SQL
Learn How to Perform Union in SQL?
Learn about Aggregate Functions in SQL
Learn about Stored Procedures in SQL
Learn How To Compare Two Or More Datetime Entities In SQL With Examples
Constraints in SQL
Find Nth Highest Salary in SQL
Triggers in SQL: An Overview and Example
SQL Commands-An Introduction
Difference Between SQL and NoSQL
SQL WITH Clause – Tutorial and Examples
Introduction To SQL: A Complete Guide
SQL Window Function
SQL Subqueries
PL/SQL Explained
GROUP BY in SQL
ORDER BY in SQL
Rename column name in SQL
Char and Varchar in SQL
Introduction
Occasionally, we might want to rename our table to something more appropriate. To rename the table, we can use ALTER TABLE for this purpose.
Syntax(Oracle,MySQL,MariaDB):
ALTER TABLE table_name |
Columns can also be given new name with the use of ALTER TABLE.
Syntax(MySQL, Oracle):
ALTER TABLE table_name |
Syntax(MariaDB):
ALTER TABLE table_name ExampleConsider the following table:
To rename ID column(The first column) to user_id the following syntax can be used:
Output:
write your code here: Coding Playground When renaming a column in a table, be cautious. You run the risk of destroying database dependencies when you use ALTER TABLE to rename columns. Instead of using ALTER TABLE to rename a column, a database refactoring tool will take care of all the dependents and update them with the new column name. If you have a tiny database you may not need to worry, but it is crucial to keep in mind. ConclusionIn this article, you have learned how to use ALTER TABLE to add a column and rename a column in a table. Mark Lesson Complete (Rename column name in SQL) |