Databases

ALTER TABLE Statement

Tri Nguyen | August 01, 2011 | ADD COMMENT
ADD A COLUMN IN A TABLE
ALTER TABLE table_name
ADD column_name datatype default value
Example:
ALTER TABLE users
ADD email nvarchar(50) default N''
This example add an email column to the users table and also set its default value empty string. Setting default value is relatively important; otherwise, it'll result in error if the users table currently has existing records.
DELETE A COLUMN IN A TABLE
ALTER TABLE table_name
DROP COLUMN column_name

CHANGE THE DATATYPE OF A COLUMN IN A TABLE
ALTER TABLE table_name
ALTER COLUMN column_name datatype