Postgres – Update and delete in PostgreSQL



Postgres – Update and delete in PostgreSQL

Postgres - Update and delete in PostgreSQL

The SQL DELETE command is used to remove rows from tables, functioning as the complementary action to INSERT. In order to remove rows from a table, you must identify the rows you wish to target by providing match criteria within a WHERE clause.

The basic syntax looks like this:

DELETE FROM my_table
WHERE condition
For instance, to every row in our employee table that has its first_name set to Abigail, we could type this:

DELETE FROM employee
WHERE first_name = ‘Abigail’;
DELETE 1
The return value here indicates that the DELETE command was processed with a single row being removed.

As with the INSERT command, you can return the affected rows or specific columns from the deleted rows by adding a RETURNING clause:

DELETE FROM my_table
WHERE condition
RETURNING *

he basic syntax of the UPDATE command looks something like this:

UPDATE my_table
SET
column1 = value1,
column2 = value2
WHERE
id = 1;
As shown above, the basic structure involves three separate clauses:

specifying a table to act on,
providing the columns you wish to update as well as their new values, and
defining any criteria PostgreSQL needs to evaluate to determine which records to match
In the basic template above, we demonstrated a style assigning values to columns directly. You can also use the column list syntax too, as is often seen in INSERT commands.

For instance, the example above could also be specified like this:

UPDATE my_table
SET (column1, column2) =
(value1, value2)
WHERE
id = 1;

sql tutorial,learn sql,sql for beginners,mysql,sql basics,sql server,sql tutorial for beginners,SQL,Structured Query Language, Postgres

#postgres , #postgresql, #postgresql tutorial, #postgres tutorial, #what is postgresql, #what is postgres, #history of postgresql
#postgressql, #postgresql tutorial for beginners, #postgresql course, postgres, postgresql,postgresql tutorial, postgres tutorial, what is postgresql, what is postgres, history of postgresql, postgressql, postgresql tutorial for beginners, postgresql course