Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
I want to rename a column (Don't need to change its type or constraints, only its name) in an SQL database using SQL, Is it possible if so, how can I do that?

This is just for any of the database pretending to support the SQL, I am only seeking for an SQL-specific query which can work despite the actual database implementation.

1 Answer

0 votes
by (12.7k points)

On PostgreSQL (and several other RDBMS), you can do it using the regular ALTER TABLE statement:

=> SELECT * FROM Test1;
 id | foo | bar 
----+-----+-----
  2 |   1 |   2

=> ALTER TABLE Test1 RENAME COLUMN foo TO baz;
ALTER TABLE

=> SELECT * FROM Test1;
 id | baz | bar 
----+-----+-----
  2 |   1 |   2

Want to learn more concepts related to SQL? Join this SQL Course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...