SQL ALTER

ALTER is used to add, delete, or modify columns in a table.

SQL Syntax ALTER

To add a new column to a table

ALTER TABLE tableName ADD columnName columnType

To delete a column in a table

ALTER TABLE tableName DROP COLUMN columnName

To modify the datatype of a column in a table

ALTER TABLE tableName ALTER COLUMN columnName columnType

Examples of SQL ALTER

pernamesurnamenickname
1HARRYCLARKWHITE
2HARRYSMITHJOHNSON
3JOHNBROWNANDERSON

Given the following table of 'people', we add a new column, called 'DateOfBirth'

ALTER TABLE people ADD DateOfBirth date

pernamesurnamenicknameDateOfBirth
1HARRYCLARKWHITE
2HARRYSMITHJOHNSON
3JOHNBROWNANDERSON

If we change the data type of column 'date', and set type 'year' instead of type 'date'

ALTER TABLE people ALTER COLUMN DateOfBirth year

If we delete the column 'DateOfBirth' and leave it like that at first

ALTER TABLE people DROP COLUMN DateOfBirth
pernamesurnamenickname
1HARRYCLARKWHITE
2HARRYSMITHJOHNSON
3JOHNBROWNANDERSON