The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
To add a column in a table, use the following syntax:
To delete a column in a table, use the following syntax (Note: some database systems don't allow deleting a column):
To change the data type of a column in a table, use the following syntax:
Look at the "Persons" table:
Now we want to add a column named "DateOfBirth" in the "Persons" table.
We use the following SQL statement:
Note: the new column, "DateOfBirth", is of type date and is going to hold a date. The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete Data Types reference.
The "Persons" table will now like this:
Now we want to change the data type of the column named "DateOfBirth" in the "Persons" table.
Note: the "DateOfBirth" column is now of type year and is going to hold a year in a two-digit or four-digit format.
Next, we want to delete the column named "DateOfBirth" in the "Persons" table.
Your Query was successfully sent!