SQL Alter Table
In an earlier lesson, we created a table with the CREATE TABLE
command. In this lesson, we will modify the table using the ALTER TABLE
command.
Add a Column
SQL syntax
Here's the syntax for adding a column.
Example SQL Statement
And here's a SQL statement that adds a column called age
to the Individual
table.
Change the Datatype
SQL syntax
To change the data type, use ALTER COLUMN
instead of ADD
.
Example SQL Statement
Here, we change the datatype of the age
column to numeric
.
Drop a Column
"Dropping" a column means removing or deleting that column.
SQL syntax
Use DROP COLUMN
followed by the name of the column you want to drop.
Example SQL Statement
Here, we drop the age
column that we added above.