Home >Database >SQL >Statements to modify table data in sql

Statements to modify table data in sql

下次还敢
下次还敢Original
2024-04-28 10:09:131127browse

There are two statements in SQL that modify table data: UPDATE statement: used to update specified row data, the syntax is UPDATE table_name SET column = value WHERE condition;. DELETE statement: used to delete specified rows, the syntax is DELETE FROM table_name WHERE condition;.

Statements to modify table data in sql

SQL statement to modify table data

In SQL, there are two main statements to modify table data:

1. UPDATE statement

Purpose: Update the data of the specified row in the table.

Syntax:

<code class="sql">UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;</code>

Example: Update the salary of the employee named "John Smith" in the table "employees":

<code class="sql">UPDATE employees
SET salary = 50000
WHERE name = 'John Smith';</code>

2. DELETE statement

Purpose: Delete the specified row from the table.

Syntax:

<code class="sql">DELETE FROM table_name
WHERE condition;</code>

Example: Delete the customer with ID 10 from the table "customers":

<code class="sql">DELETE FROM customers
WHERE id = 10;</code>

Note:

  • These statements will permanently modify data in the database, so please check carefully before use.
  • Conditional clauses are very important for selecting rows to modify or delete. Without a conditional clause, all rows in the entire table will be modified or deleted.
  • Multiple modification or delete operations can be combined into a single transaction to ensure atomicity.

The above is the detailed content of Statements to modify table data in sql. 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