Delete record change

The change statement of the record is as follows:

UPDATE table name
SET field name = condition to change
WHERE field name = existing attribute value;

Single record change

When there is a condition that searches only a single field in the WHERE clause, the query changes only for one record. Try the student table you used previously Let's increase the rank value of mickey by 4 using the UPDATE statement. Then select the student_db database Enter the following:

UPDATE student SET rank = rank + 4 WHERE name = 'mickey';

This adds the number 4 to the rank of the records named mickey. The result then changes to:

mysql image

Mickey's ranking increased from 9 to 4, making it 11. This single change is called a single record change. So this time change the entire record Try changing the rank of the whole. Apply +3 and remove the condition.

UPDATE student SET rank = rank +3;

Entering 3 adds 3 to all ranks, as shown below. When you execute the update statement without any condition as above, think again and think again. That may be the membership information of the service that is actually being service, not just data.

You can get a job later, become a programmer, and change the names of all the customers in the real service to mickey. So, if you do not know the actual service, please make a backup before running it, or check with the server administrator how many hours the db backup is performed. And if you make a mistake and you only need to change some records, or if you change the value of every record, don't hide it and report it immediately. Mistakes can be corrected and solved immediately, but if you hide them and over time, the data may get tangled and your teammates or the whole office worker may have to work overtime and work the weekend.

mysql image

Now let's delete the record.

DELETE FROM table name WHERE = 조건;

So from deleting a single record It only deletes one record. Let's delete mike wazowski.

DELETE FROM student WHERE name = 'mike wazowski';
mysql image

mike wazowski has been removed.

Again,
there is a situation where you need to get a job later and become a programmer and delete someone from the real service.
So, if you do not know the actual service, please make a backup before running it, or check with the server administrator how many hours the db backup is performed.
And if you have accidentally deleted only someone's record and you deleted all the records without using a conditional statement, please report it immediately.
Mistakes can be corrected and solved immediately, but if you hide them and over time, the data may get tangled and your teammates or the whole office worker may have to work overtime and work the weekend.
In the worst case, you may have to pay for damages.

Now let's delete the people whose ranks are between 8 and 14.
You only need to have a condition in WHERE. Simple!

DELETE FROM student WHERE rank >= 8 AND rank <= 14;
mysql image

All those who met the conditions were deleted. How do you delete an entire record?
Simplest.

DELETE FROM table name;

It looks like this:

DELETE FROM student;

Really say once again. It's really last.
There is a situation where you need to get a job later and become a programmer and delete someone from the real service.
So, if you do not know the actual service, please make a backup before running it, or check with the server administrator how many hours the db backup is performed.
And if you have accidentally deleted only someone's record and you deleted all the records without using a conditional statement, please report it immediately.
Mistakes can be corrected and solved immediately, but if you hide them and over time, the data may get tangled and your teammates or the whole office worker may have to work overtime and work the weekend.
In the worst case, you may have to pay for damages.

mysql image

All deleted.
In the next lesson, we will look at database backup and restore.