Skip to main content

SQL ALTER TABLE Statement

Body

The ALTER TABLE statement is used to change the structure of an existing table like adding, deleting, or modifying of column.

SQL ALTER TABLE Syntax

To add a new column to the existing table use the following syntax:
ALTER TABLE table_name ADD column_name datatype

To remove a column from a table use the following syntax:
ALTER TABLE table_name DROP TABLE column_name

To modify a column from a table use the following syntax:
ALTER TABLE table_name ALTER COLUMN column_name datatype

Consider the following table for this exercise

Users

Firstname Lastname Salary DeptID
John Smith 1000 1
Mathew Simon 3000 1
Bill Steve 2200 1
Amanda Rogers 1800 2
Steve Hills 2800 2
Steve jobs 2400 2
bill cosby 700 3

Example # 1

ALTER TABLE Users ADD Phone INT

Result of the Query

Firstname Lastname Salary DeptID Phone
John Smith 1000 1  
Mathew Simon 3000 1  
Bill Steve 2200 1  
Amanda Rogers 1800 2  
Steve Hills 2800 2  
Steve jobs 2400 2  
bill cosby 700 3  

The resulted table is now formed with an additional column of Phone that we created with the alter table statement.

Comments

Submitted byAnonymous (not verified)on Sat, 02/09/2013 - 12:18

Its not good.Its very Good and helpful. Thanks sourcecodeester.com

Add new comment