How to Delete/Add a column in an Existing Table in MySQL

In this tutorial, we will learn How to delete/Add a column in an existing table in MySQL, as adding and deleting are very important for a database. These all are done by DDL Data Defination Language as we are dealing with the manipulation of the Structure of the table.

The update is the query that is used for making changes in the table either editing, adding, or deleting all are done by updating along with certain clauses like where and in, between, having to limit the access of data, We do not use these clauses then we may lead to the lost whole of the table as to understand SQL about a specific column that need manipulation.

Delete

Alter Command

The update is a DDL is used for dealing with the manipulation of data stored in a table and even for getting the modification things is done by the update command

There are certain actions that could be done by Update that we are going to discuss here.

Delete

It is a way to remove existing Columns from a table using the update command for permanent to execute the same following the code given below and learn. Provided for deleting a column there must be that column exists.

ALTER TABLE Test DROP COLUMN Branch;

It will drop /Delete the column Branch

ADD

Adding a new column to the existing table is also done by Alter Command where we need to specify the data type and size of data that could be stored in the column. To understand it better look at the command given below and learn.

ALTER TABLE Test   
ADD COLUMN Phone_number VARCHAR(20) NOT NULL AFTER Name;

Where we have added the column name phone_number with the data type Varchar and the size of 20 with a condition that it can not store any null Value and the location of the column is also specified here that is after the name.

Things that we need to keep in mind is that we need to add the content that is adding data to only those columns which are already created we can not enter any extra data in between. We have to make a column for the data we want to enter or not and that is the reason we have added a column is required

Although such problems are not there for detection as we are simply deleting the complete column and the whole data stored in that column can be deleted in just one step which again might create some problems.

Deleting a column leads to the loss of data of the whole column which can not be recovered anymore.

There different other operation which could be perform in DDL as changing the data type, Name of some column etc

 

To learn more about Delete/Add a column in an Existing Table in MySQL visit. DDL command for adding and deleting

Also, visit MySQL Problems And Tutorials to learn more about MySQL and to learn more about programming Languages, tutorials, and concepts visit beta python for programming Solutions to solve the problems faced during solving the problems and keep learning.

 

Leave a Comment

%d bloggers like this: