What is the standard SQL way to rename a column?
0
votes
1
answer
1386
views
So far I've seen
ALTER TABLE RENAME
, ALTER TABLE CHANGE
and ALTER TABLE MODIFY
.
What I'm trying to achieve is something like ALTER TABLE my_table RENAME col_old_name TO col_new_name
, which can be a case of modifying a column.
[SQLite](https://www.sqlite.org/lang_altertable.html) goes with RENAME
.
[MariaDB](https://mariadb.com/kb/en/alter-table/) and [MySQL](https://dev.mysql.com/doc/refman/8.0/en/alter-table.html) have all three.
[Postgres](https://www.postgresql.org/docs/current/ddl-alter.html#id-1.5.4.8.11) goes with RENAME
.
[Oracle](https://docs.oracle.com/database/121/SQLRF/statements_3001.htm#i2103924) has RENAME
and MODIFY
.
Standards are unkown to [SQL Server](https://learn.microsoft.com/en-us/sql/relational-databases/tables/rename-columns-database-engine?view=sql-server-ver15) .
What is the database-agnostic way for renaming (or generally altering) a column?
Maybe I'm erroneously expecting the standard to cover DDL operations as well? I have code that works with multiple databases so would rather make the SQL part as portable as possible.
Asked by vesperto
(135 rep)
Mar 17, 2022, 10:35 AM
Last activity: Mar 17, 2022, 01:39 PM
Last activity: Mar 17, 2022, 01:39 PM