- SQL Tutorial
- SQL Tutorial
- SQL Display Data
- SQL Update Records
- SQL Delete Record
- SQL Alter Table
- SQL Join Tables
- SQL Auto Increment
- SQL Drop Table/Database
- Computer Programming
- Learn Python
- Python Keywords
- Python Built-in Functions
- Python Examples
- Learn C++
- C++ Examples
- Learn C
- C Examples
- Learn Java
- Java Examples
- Learn C#
- Learn Objective-C
- Web Development
- Learn HTML
- Learn CSS
- Learn PHP
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.
- Adding new columns to an existing table.
- Deleting specific column in an existing table.
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;
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.
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;
ALTER TABLE customer DROP COLUMN country;
The above SQL query will drop or delete the column named "country" from the table named "customer."
« Previous Topic Next Topic »