Alter Table in SQL | Add and Delete Existing Column in Existing Table in SQL

This post describes how to do the following task in SQL.

The SQL ALTER TABLE statement can be used to do both of the above two things.

Adding new columns to an existing table in SQL

Sometime a table has already existed in your database, and you need to add one or more columns to it without destroying the table's data. To achieve this task, there is an ALTER TABLE statement available in SQL whose general form is

ALTER TABLE tableName
ADD columnName dataType;

For example:

ALTER TABLE customer
ADD country varchar(50);

After executing the above SQL query, you will have a newly added column named "country" in your existing table named "customer." Here is the snapshot after executing the above SQL query, for your understanding.

sql alter table example

Deleting specific column in an existing table in SQL

Here is the general form of the SQL ALTER TABLE statement that is used when we need to delete an existing column in an existing table.

ALTER TABLE tableName
DROP COLUMN columnName;

For example:

ALTER TABLE customer
DROP COLUMN country;

The above SQL query will drop or delete the column named "country" from the table named "customer."

SQL Online Test


« Previous Topic Next Topic »