Once a table is created in the database, there are many condition where we have to change the structure of the table.
Add a column
Drop a column
Change a column name
Change the data type for a column
changing the primary key specification
Syntax
ALTER TABLE "table_name" [alter specification]
Let's use above syntax with "customer" table
Column Name
Data Type
First_Name
char(50)
Last_Name
char(50)
Address
char(50)
City
char(50)
Country
char(25)
Birth_Date
date
If we want to add a column called "Gender" to this table. Syntax given below:
ALTER table customer add Gender char(1)
If we want to rename "Address" to "Addr".Syntax given below:
ALTER table customer change Address Addr char(50)
If we want to change the data type for "Addr" to char(30).Syntax given below:
ALTER table customer modify Addr char(30)
If we want to drop the column "Gender".Syntax given below:
ALTER table customer drop Gender
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords alter table modify column, alter table sql, alter table rename,
alter table drop column, alter table mysql, alter table in oracle,
alter table syntax