"DELETE" COMMAND AND HOW TO GET RID FROM DELETE TWO STEP PROCESS USING "UPDATE" COMMAND
DELETE Command:
It is used to delete the data from the table.
SYNTAX: DELETE FROM table_name WHERE condition;
Example: DELETE FROM customer WHERE Address='Bhopal';
This doesn't delete a single column, it delete the whole row that contain this address.
Rules Of DELETE:
1. DELETE is not use to delete the value from a single column or
tableful column.
2. DELETE can be used to delete a single row or multiple rows,
depending on WHERE clause.
- Use DELETE carefully. Make sure to include a precise WHERE clause to target the exact rows you really want to delete.
Trouble with delete
Suppose we want to delete the data of Bhanu because his salary increases to 70000. And if we apply the DELETE statement then it will delete the whole data of Bhanu and we didn't want that.
To get rid of this problem we use INSERT-DELETE.
In this firstly we Insert the data and then Delete the old records from the table.
For this, lets see the example given below:

- In above example if two person have same salary then the applied query delete the two records. So, at that time we need to be careful of DELETE.
Must Read :How to create DataBase in MySQL, Tables in MySQL database and How To Insert Data In The Database.
UPDATE Command:
SYNTAX: UPDATE table_name SET col_x='new value', col_y='another value' WHERE col='value';
Suppose we want to update the information of the customer having ID=3. Then, it is done as:
We can use different type of operation with UPDATE.
Example: To increase the age by one.
In above example whole table is updated, if we want to update the age of some customer then we can do this with the help of WHERE clause.
QUESTIONS :
1. What happen if we leave out the where clause?
2. What is the need of UPDATE over INSERT-DELETE?
Must Read :How to create DataBase in MySQL, Tables in MySQL database and How To Insert Data In The Database.
In case of any query and any error related to content mail to: anshika.chaudhary2510@gmail.com
Previous Next
No comments: