MySql Alter, Delete, Drop and Update Table

MySql Update Statement Alter word indicates to modify or change something. In MySQL, Alter command is used to alter the existing Table. The table must be present for using Alter Command. MySql alter command helps to the following Operations.

1.) Alter statement helps to add the column to the table.

2.) Helps to delete a column from the table.

3.) Modify the filed or column name.

SQL Add Column Syntax

ALTER TABLE [Name of the table]
ADD [Name of the column] datatype;

Firstly you need to learn mysql create table

Now we are taking the table name as “MyFirst_Table” that exist in “test_db”.

MyFirst_Table has four columns

1.) MyFirst_Table_id
2.) MyFirst_Table_firstname
3.) MyFirst_Table_surname
4.) MyFirst_Table_fname

MySqlCreateTable

Mysql Add Column – Alter Table

In the following command, we will add one more column “MyFirst_Table_result”.  Alter table command helps to add the column in the table.

ALTER TABLE MyFirst_Table 
ADD MyFirst_Table_result varchar(200);

Comman has run successfully. Now we can see table by using select query.

Select * from MyFirst_Table;
MySql Create Table

MySQL Update Statement

MySql Update Statement is used to edit or update the value of any field or column. We can update the value of the column by giving some particular condition.

Update Syntax in MySQL

UPDATE table_name
SET column_1 = value_1, column_2 = value_2, column_3 = value_3, .....
WHERE condition;

Note: If we ignore where condition, all rows will be reflected with the set value. We have the following entries in the Table.

MySql Create Table

MySQL Update Statement Example

In this example, we will update the value of “MyFirst_Table_result” whose id is 3.

UPDATE MyFirst_Table
SET MyFirst_Table_result = 'pass'
WHERE MyFirst_Table_id=3;
MySql Update Statement

Delete Column SQL

Delete keyword is used to delete column and table. To delete the particular row we need to mention particular condition same as update statement.

Delete Column Sql Syntax

DELETE FROM Table_Name WHERE condition;

In the following example, we will delete the row which has MyFirst_Table_id equals to 3.

DELETE FROM MyFirst_Table WHERE MyFirst_Table_id=3;
Delete Column SQL

MySQL Drop Table

Drop keyword is used to permantly delete table from Database. This command delete the whole data from table.

Note: Becarefull for use this command.

MySQL Drop Table Syntax

DROP TABLE Table_Name;

MySQL Truncate Table

The truncate command is used to delete the data of a particular table. The table will exist in the Database.

MySQL Truncate Table Syntax

TRUNCATE TABLE Table_Name;

Drop Database MYSQL

Drop Database command is used to permanently delete Database. This command will delete whole data from the database including tables and all.

DROP DATABASE Database_Name;

More Related Post

Thanks for the reading post. I hope you like and understand the post. If you have any doubt regarding this post please comment below.

02 comments on “MySql Alter, Delete, Drop and Update Table

Leave a comment

Your email address will not be published. Required fields are marked *

0 0 0
FOLLOW ON