INSERT, UPDATE and DELETE in SQL

Содержание

SQL uses INSERT, UPDATE, and DELETE statements to modify data.

INSERT

The INSERT statement inserts rows into a table.

It has two forms. The first allows you to insert strings explicitly specifying their value:

For both forms, specifying a list of columns is optional. The DEFAULT VALUES parameter inserts default values for all columns.

The second form allows you to insert the result set of a SELECT statement or stored procedure into a table:

UPDATE

The UPDATE statement lets to update table rows:

This query selects the rows of the tab_name table for modification according to the condition in the WHERE clause.

SET clause allows to change the column values of each modified row.

FROM allows you to select rows for modification based on a more complex condition using several linked pages.

DELETE

The DELETE statement removes rows from a table:

All rows that satisfy the condition in the WHERE clause are removed. The WHERE clause can contain a subquery for a more complex condition, or you can use a slightly different form of the statement (the semantics is similar to the UPDATE statement):