FACTOID # 174: One in three Italian babies is born by caesarean section.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Delete (SQL)

An SQL DELETE statement removes one or more records from a table. A subset may be defined for deletion using a condition, otherwise all records are removed. SQL (IPA: or ) is a computer language designed for the retrieval and management of data in relational database management systems, database schema creation and modification, and database object access control management. ...

Contents

Usage

The DELETE statement has this syntax:

DELETE FROM table_name [WHERE condition]

Any rows that match the WHERE condition will be removed from the table. If the WHERE clause is omitted, all rows in the table are removed. The DELETE statement should thus be used with caution! A WHERE statement in SQL specifies that an SQL command should only be ran on rows that meet a specified condition. ...


The DELETE statement does not return any rows; that is, it will not generate a result set. An SQL result set is a set of rows from a database, as well as meta-information about the query such as number of results returned and the column names. ...


Executing a DELETE statement may cause triggers to run that may cause deletes in other tables. For example, if two tables are linked by a foreign key and rows in one table were deleted, then it is common that rows in the second table would also have to be deleted to maintain referential integrity. For a more general discussion of how cascading deletes are handled, see propagation constraint. A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database. ... In the context of relational databases, a foreign key is a referential constraint between two tables[1]. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. ... An example of a database that has not enforced referential integrity. ... According to Beynon-Davies (2004, p. ...


Examples

Delete rows from table pies where the column flavour equals Lemon Meringue:

 DELETE FROM pies WHERE flavour='Lemon Meringue'; 

Delete rows in trees, if the value of height is smaller than 80.

 DELETE FROM trees WHERE height < 80; 

Delete all rows from mytable:

 DELETE FROM mytable; 

Delete rows from mytable using a subquery in the where condition:

 DELETE FROM mytable WHERE id IN (SELECT id FROM mytable2) 

Delete rows from mytable using a list of values:

 DELETE FROM mytable WHERE id IN (value1, value2, value3, value4, value5) 

Example with related tables

Suppose there is a simple database that lists people and addresses. More than one person can live at a particular address and a person can live at more than one address (this is an example of a many-to-many relationship). The database only has three tables, person, address, and pa, with the following data:


person

pid name
1 Joe
2 Bob
3 Ann

address

aid description
100 2001 Main St.
200 35 Pico Blvd.

pa

pid aid
1 100
2 100
3 100
1 200

The pa table relates the person and address tables, showing that Joe, Bob and Ann all live at 2001 Main Street, but Joe also takes up residence on Pico Boulevard.


In order to remove joe from the database, two deletes must be executed:

 DELETE FROM person WHERE pid=1 DELETE FROM pa WHERE pid=1 

To maintain referential integrity, Joe's records must be removed from both person and pa. The means by which integrity is sustained can happen differently in varying relational database management systems[citation needed]. It could be that beyond just having three tables, the database also has been set up with a trigger so that whenever a row is deleted from person any linked rows would be deleted from pa. Then the first statement:

 DELETE FROM person WHERE pid=1 

would automatically trigger the second:

 DELETE FROM pa WHERE pid=1 

Related Commands

Deleting all rows from a table can be very time consuming. Some DBMS offer a TRUNCATE command that works a lot quicker, as it only alters metadata.


External links

  • Startup Manual Oracle for beginners (Spanish)
  • MySQL tutorial
A database management system (DBMS) is computer software designed for the purpose of managing databases based on a variety of data models. ... A data model is not just a way of structuring data: it also defines a set of operations that can be performed on the data. ... Database normalization, sometimes referred to as canonical synthesis, is a technique for designing relational database tables to minimize duplication of information and, in so doing, to safeguard the database against certain types of logical or structural problems, namely data anomalies. ... Database tables/indexes are typically stored in memory or on hard disk in one of many forms, ordered/unordered Flat files, ISAM, Heaps, Hash buckets or B+ Trees. ... According to Elmasri and Navathe (2004, p. ... An example of a database that has not enforced referential integrity. ... Relational algebra, an offshoot of first-order logic, is a set of relations closed under operators. ... The relational calculus refers to the two calculi, the tuple calculus and the domain calculus, that are part of the relational model for databases and that provide a declarative way to specify database queries. ... A relational database is a database that conforms to the relational model, and refers to a databases data and schema (the databases structure of how those data are arranged). ... A relational database management system (RDBMS) is a database management system (DBMS) that is based on the relational model as introduced by E. F. Codd. ... The relational model for database management is a database model based on predicate logic and set theory. ... An object-relational database (ORD) or object-relational database management system (ORDBMS) provides a relational database management system that allows developers to integrate a database with their own custom data-types and methods. ... In computer science, transaction processing is information processing that is divided into individual, indivisible operations, called Each transaction must succeed or fail as a complete unit; it cannot remain in an intermediate state. ... This article is principally about managing and structuring the collections of data held on computers. ... For other uses, see acid (disambiguation). ... The Greek lowercase omega (ω) character is historically used by academics to represent Null in relational databases. ... In the relational model a candidate key of a relation variable (relvar) is a set of attributes of that relvar such that (1) at all times it holds in the relation assigned to that variable that there are no two distinct tuples with the same values for these attributes and... In the context of relational databases, a foreign key is a referential constraint between two tables[1]. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. ... In database design, a primary key is a value that can be used to identify a unique row in a table. ... A superkey is defined in the relational model as a set of attributes of a relation variable (relvar) for which it holds that in all relations assigned to that variable there are no two distinct tuples (rows) that have the same values for the attributes in this set. ... A surrogate key is a unique primary key generated by the relational database management system that is not derived from any data in the database and whose only significance is to act as the primary key. ... A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database. ... In database theory, a view is a virtual or logical table composed of the result set of a query. ... In relational databases, SQL databases, and flat file databases, a table is a set of data elements (values) that is organized using a model of horizontal rows and vertical columns. ... In database packages, the term cursor refers to a control structure for the successive traversal (and potential processing) of records in a result set as returned by a query. ... In in the field of databases in computer science, a transaction log (also database log or binary log) is a history of actions executed by a database management system to guarantee ACID properties over crashes or hardware failures. ... A database transaction is a unit of interaction with a database management system or similar system that is treated in a coherent and reliable way independent of other transactions. ... A database index is a data structure that improves the speed of operations in a table. ... A stored procedure is a subroutine available to applications accessing a relational database system. ... A partition is a division of a logical database or its constituting elements into distinct independent parts. ... SQL (IPA: or ) is a computer language designed for the retrieval and management of data in relational database management systems, database schema creation and modification, and database object access control management. ... An SQL SELECT statement returns a result set of records from one or more tables. ... A SQL INSERT statement adds one or more records to a table in a relational database. ... An UPDATE statement in SQL changes data in one or more records in a relational database management system. ... Wikipedia does not have an article with this exact name. ... A JOIN clause in SQL combines records from two tables in a relational database and results in a new (temporary) table, also called a joined table. Structured Query Language (SQL:2003) specifies two types of joins: inner and outer. ... In SQL the UNION operator combines the results of two SQL queries into a single table of all matching rows. ... A CREATE statement in SQL creates an object inside of a relational database management system (RDBMS). ... A DROP statement in SQL removes an object from a relational database management system (RDBMS). ... It has been suggested that this article or section be merged into Database transaction. ... A COMMIT statement in SQL ends a transaction within a relational database management system (RDBMS) and makes all changes visible to other users. ... In database technologies, a rollback is an operation which returns the database to some previous state. ... The Truncate statement removes all the data from a table. ... An ALTER statement in SQL changes the properties of an object inside of a relational database management system (RDBMS). ... A relational database is a database that conforms to the relational model, and refers to a databases data and schema (the databases structure of how those data are arranged). ... A simple diagram depicting conversion of a CSV-format flat file database table into a relational database table. ... A deductive database system is a database system which can make deductions (ie: infer additional rules or facts) based on rules and facts stored in the (deductive) database. ... A dimensional database is one which, rather than representing data in multiple relations (as a relational database does), represents key data entities as different dimensions. ... In a hierarchical data model, data are organized into a tree-like structure. ... The network model is a database model conceived as a flexible way of representing objects and their relationships. ... In an object database (also object oriented database), information is represented in the form of objects as used in object-oriented programming. ... An object-relational database (ORD) or object-relational database management system (ORDBMS) provides a relational database management system that allows developers to integrate a database with their own custom data-types and methods. ... A temporal database is a database management system with built-in time aspects, e. ... An XML database is a data persistence software system that allows data to be imported, accessed and exported in the XML format. ... In computer science -- more specifically, in the field of databases -- concurrency control is a method used to ensure that database transactions are executed in a safe manner (i. ... A data dictionary is a set of metadata that contains definitions and representations of data elements. ... JDBC is an API for the Java programming language that defines how a client may access a database. ... In computing, Open Database Connectivity (ODBC) provides a standard software API method for using database management systems (DBMS). ... Query languages are computer languages used to make queries into databases and information systems. ... The query optimizer is a component of database management system that is used to analyzes queries submitted to database server for execution, and then determines the optimal way to execute the query. ... A query plan (or query execution plan) is an set of steps used to access information in a SQL relational database management system. ... The following is a list of object-oriented database management systems. ... This article or section is not written in the formal tone expected of an encyclopedia article. ... See DBMS for a shorter list of “typical”, representative database management systems. ... The following tables compare general and technical information for a number of relational database management systems. ...

  Results from FactBites:
 
SQL Introduction (522 words)
SQL is a standard computer language for accessing and manipulating databases.
SQL statements are used to retrieve and update data in a database.
SQL (Structured Query Language) is a syntax for executing queries.
SQL - Wikipedia, the free encyclopedia (2210 words)
SQL was adopted as a standard by the ANSI (American National Standards Institute) in 1986 and ISO (International Organization for Standardization) in 1987.
One joke about SQL is that "SQL is neither structured, nor is it limited to queries, nor is it a language." This is founded on the notion that pure SQL is not a classic programming language since it is not Turing-complete.
However, it also makes it possible for SQL source code to be produced (and optimized) by software, leading to the development of a number of natural language database query languages, as well as 'drag and drop' database programming packages with 'object oriented' interfaces.
  More results at FactBites »


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m