Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Databases - Practical PostgreSQL
Previous Page Home Next Page

DELETE

Name

DELETE -- Removes rows from a table.

Synopsis

  DELETE FROM [ ONLY ] 
table
 [ WHERE 
condition
 ]

Parameters

table

The name of the table from which you are deleting rows.

condition

The condition that identifies rows to be deleted. This is just like the WHERE clause of a SELECT query; refer to SELECT" for more information on constructing conditions. Note that not providing a WHERE condition will cause all rows to be deleted from a table.

Results

DELETE count

The message returned if the deletion of any rows is successful. The count is the number of rows that were removed from the table. If that number is 0, then either no rows met the specified condition, or there were no rows in the table to be removed.

Description

Use DELETE to remove rows from a table. Only rows that match a condition you specify will be deleted. To delete all rows from a table, do not specify a condition. Issuing a DELETE with no condition results in all rows being deleted from the target table. You are then be left with an empty table.

Note: Use TRUNCATE to empty a table more efficiently than with an unconditional DELETE statement.

Use the ONLY clause to prevent the deletion of rows from tables that inherit from the target table. ONLY restricts the delete operation to only the target table. Otherwise, the delete operation will affect not only the target table, but all tables that inherit from it.

Example

The following syntax removes all shipped orders from the shipments table that were placed by customer ID 142, and that were shipped before August 7, 2001:

booktown=# 
DELETE FROM shipments

booktown-# 
       WHERE customer_id = 142

booktown-# 
       AND ship_date < '2001-08-07';

DELETE 1
Databases - Practical PostgreSQL
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire