Leilin Peng Share: MySQL UPDATE query

  If we need to modify or update the data in MySQL, we can use the SQL UPDATE command to operate. .

  grammar

  The following is the UPDATE command to modify MySQL Data Sheet Data Universal SQL syntax:

  UPDATE table_name SET field1=new-value1, field2=new-value2

  [WHERE Clause]

  You can update one or more fields at the same time.

  You can specify any condition in the WHERE clause.

  You can also update data in a separate table.

  When you need to update the data specified in the table rows WHERE clause is very useful.

  By the command prompt to update the data

  Below we will use the WHERE clause in the SQL UPDATE command to update codercto_tbl data specified in the table:

  Examples

  The following examples will update the data table codercto_id codercto_title field value is 3:

  SQL UPDATE statement:

  mysql> UPDATE codercto_tbl SET codercto_title='学习 C++' WHERE codercto_id=3; Query OK, 1 rows affected (0.01 sec) mysql> SELECT * from codercto_tbl WHERE codercto_id=3; +-----------+--------------+---------------+-----------------+ | codercto_id | codercto_title | codercto_author | submission_date | +-----------+--------------+---------------+-----------------+ | 3 | 学习 C++ | CODERCTO.COM | 2016-05-06 | +-----------+--------------+---------------+-----------------+ 1 rows in set (0.01 sec)

  From the results point of view, codercto_id to codercto_title 3 has been modified.

  Use PHP script to update data

  PHP function used mysqli_query () to execute SQL statements, you can use SQL UPDATE statement or do not use the WHERE clause.

  Note: Do not use the WHERE clause to all data in the table is updated, so be careful.

  This function is in the mysql> command prompt execute SQL statements effect is the same.

  Examples

  The following examples will update the data codercto_title codercto_id field 3.

  MySQL UPDATE statement tests:

  

  Click to see all MySQL Tutorial Articles: https://www.codercto.com/courses/l/30.html (edit: Leilin Peng Source: network intrusion deleted)

Guess you like

Origin www.cnblogs.com/pengpeng1208/p/10984401.html