Saturday, July 23, 2011

Alter Table Rename Column Syntax


In MySQL, the SQL syntax forALTER 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 TABLEsection:
Table customer
Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedate

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 NameData Type
First_Namechar(50)
Last_Namechar(50)
Addrchar(50)
Citychar(50)
Countrychar(25)
Birth_Datedate



0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server