Use UPDATE and DELETE commands in SQL to modify data: UPDATE command updates existing records, the syntax is: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;DELETE command deletes records, the syntax is: :DELETE FROM table_name WHERE condition; Be sure to use with caution because they are destructive operations. Use the WHERE clause to specify conditions to update or delete only specific rows.
Use the UPDATE
and DELETE
commands in SQL to change the data.
UPDATE
Command UPDATE
command is used to update existing records in a table. The syntax is:
<code class="sql">UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;</code>
table_name
: The name of the table to be updated. column1
, column2
, ...: The column name to be updated. value1
, value2
, ...: The new value to be updated. condition
: Specify the conditions for the rows to be updated. The default is to update all rows. Example:
<code class="sql">UPDATE customers SET name = 'John Doe', email = 'john.doe@example.com' WHERE id = 12345;</code>
This query updates the record with customer ID 12345 to have the name "John Doe" and the email "john.doe@ example.com".
DELETE
Command DELETE
command is used to delete records from a table. The syntax is:
<code class="sql">DELETE FROM table_name WHERE condition;</code>
table_name
: The name of the table from which records are to be deleted. condition
: Specify the conditions for rows to be deleted. The default is to delete all rows. Example:
<code class="sql">DELETE FROM orders WHERE order_date < '2021-01-01';</code>
This query will delete all orders with dates earlier than January 1, 2021.
UPDATE
and DELETE
commands as they are destructive operations. WHERE
clause to specify conditions to update or delete only specific rows. The above is the detailed content of Commands to modify data in sql. For more information, please follow other related articles on the PHP Chinese website!