Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PostgreSQL Table Delete

  • Removes all records from a table. But this command will not destroy the table's structure
  • Removing rows can only be done by specifying conditions that the rows to be removed have to match. If you have a primary key in the table then you can specify the exact row. But you can also remove groups of rows matching a condition, or you can remove all rows in the table at once.

--select the table what record do you want to delete
postgres=# select * from demo;                                                  
 id |   name   
----+----------
  2 | benz
  3 | benz
  1 | benz1
  4 | oracle
  5 | mysql
  6 | postgres
  7 | db2
(7 rows)
--You use the DELETE command to remove rows; the syntax is very similar to the UPDATE command
postgres=# delete from demo where id=1;                                         
DELETE 1

postgres=# select * from demo;         
 id |   name   
----+----------
  2 | benz
  3 | benz
  4 | oracle
  5 | mysql
  6 | postgres
  7 | db2
(6 rows)
--Deleting multiple rows in a table
postgres=# delete from demo where id in (2,5,7);
DELETE 3

postgres=# select * from demo;                  
 id |   name   
----+----------
  3 | benz
  4 | oracle
  6 | postgres
(3 rows)
--all rows in the table will be deleted but table structure(metadata) cannot be deleted see following example
postgres=# delete from demo;                    
DELETE 3




Comments

Popular posts from this blog

VMWARE WORKSTATION 3,4,5,6,7,8,9,10,11,12,14,15...etc LICENSE KEYS COLLECTION

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

Oracle to Postgresql migration

PostgreSQL Enterprise Manager - PEM Monitoring Tools

7 Steps to configure BDR replication in postgresql