Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PostgreSQL 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

ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated ORA-01262: Stat failed on a file destination directory Linux-x86_64 Error: 2: No such file or directory

PostgreSQL pgBadger

PostgreSQL Pgbadger Installation On Linux

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

Migrating From Oracle to PostgreSQL using ora2pg open source tools