SQL ALTER Statement

Wednesday, January 04, 2012

tags SQL

The SQL ALTER statement is used to add, modify, or delete fields in an existing database table.

Employees Table



employeeIDemployeeNameaccountCreated
1000John Smith1995-12-03 13:23:30.657
1001Fred White2001-10-12 09:41:44.125
1002Jane Scott1998-05-01 11:36:16.334
1003Samuel Williams1991-01-03 15:19:51.293

Syntax



ALTER TABLE tableName
ADD columnName dataType


ALTER TABLE tableName
ALTER COLUMN columnName dataType


ALTER TABLE tableName
DROP COLUMN columnName


Example



ALTER TABLE Employees
DROP COLUMN accountCreated


Results



employeeIDemployeeName
1000John Smith
1001Fred White
1002Jane Scott
1003Samuel Williams

The ALTER Statement used in this example deleted the 'accountCreated' field by using the DROP keyword in the statement.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook