Home  >  Article  >  Database  >  MySQL modify and delete statement operations (MYSQL statement operation tutorial 2)

MySQL modify and delete statement operations (MYSQL statement operation tutorial 2)

巴扎黑
巴扎黑Original
2017-04-28 09:31:041890browse

Modify records

To perform modification operations, you can use the UPDATE statement. The syntax format is as follows:

UPDATE data table name Set column_name = new_value1, column_name2 = new_value2,...[where condition]

Among them, the Set clause indicates the columns to be modified and their given values. The where clause is optional. If it is given, it will Specifies which rows in the record should be updated, otherwise, all rows will be updated.

For example, suppose there is a table called admin. We want to change the password of Tom in the table from 111 to 222. The statement is as follows:

UPDATE admin Set password = '222' where user = 'Tom';

Note: Be sure to ensure the correctness of the where clause when updating. Once the where clause is wrong, all changed data will be destroyed.


Delete records

In the database, if some data has lost its meaning or is wrong, it needs to be deleted To delete them, you can use the DELECT statement. The format of the statement is as follows:

DELECT from data table name where condition

Note: During the execution of this statement, if If the where condition is not specified, all records will be deleted; if the where condition is specified, the records will be deleted according to the specified conditions.

For example, suppose there is a table named admin, and now you want to delete the record information of the user name "petty" in the table. The specific statements are as follows:

DELECT from admin where user = "petty";

It is worth noting that in actual applications, when performing a delete operation, the condition for performing the deletion should generally be the data The id is not a specific field value, which can avoid unnecessary errors.

The above is the detailed content of MySQL modify and delete statement operations (MYSQL statement operation tutorial 2). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn