|
In MySQL, the SQL syntax for ALTER TABLE Rename Column is
ALTER TABLE "table_name"
Change "column 1" "column 2" ["Data Type"]
In Oracle, the syntax is,
ALTER TABLE "table_name"
RENAME COLUMN "column 1" TO "column 2"
Let's look at the example. Assuming our starting point is the "customer" table created in the CREATE TABLE section:
Table customer
| Column Name | Data Type |
| First_Name | char(50) |
| Last_Name | char(50) |
| Address | char(50) |
| City | char(50) |
| Country | char(25) |
| Birth_Date | date |
To rename "Address" to "Addr", we key in,
MySQL:
ALTER table customer CHANGE Address Addr char(50);
Oracle:
ALTER table customer RENAME COLUMN Address TO Addr;
SQL Server:
It is not possible to rename a column using the ALTER TABLE statement in SQL Server. Use sp_rename instead.
Resulting table structure:
Table customer
| Column Name | Data Type |
| First_Name | char(50) |
| Last_Name | char(50) |
| Addr | char(50) |
| City | char(50) |
| Country | char(25) |
| Birth_Date | date |
ALTER TABLE DROP COLUMN >>
Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.
Copyright 2010 1keydata.com. All Rights Reserved. Privacy Policy
|