SQL ALTER TABLE Statement

SQL ALTER TABLE statement is used to modify the table structure, you can modify column(s), add column(s), drop column(s) or work on constraints. Here we will use the tbl_employee table for practice.

In this table we will add the Address column, so we can write the below query.

ALTER TABLE tbl_employee
ADD Address varchar(20)

So you can see the last column is added with the name of Address.

To modify a column in a table you can write the below query. So we have modified data size from varchar(300) 
to varchar(500).

ALTER TABLE tbl_employee
ALTER COLUMN Address varchar(50)

If you want to drop a column from the table then you can use the below query.

ALTER TABLE tbl_employee
DROP COLUMN Address

So, the Address column will be dropped with data values in the table.

You can also work on constraints like modify, add or drop constraints with ALTER TABLE statements.

 

2020-05-12