84 lines
5.5 KiB
HTML
84 lines
5.5 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="concept" />
|
||
|
<meta name="DC.Title" content="Remove rows from a table using the DELETE statement" />
|
||
|
<meta name="abstract" content="To remove rows from a table, use the DELETE statement." />
|
||
|
<meta name="description" content="To remove rows from a table, use the DELETE statement." />
|
||
|
<meta name="DC.subject" content="data manipulation statement (DML), DELETE statement, description, statements, DELETE, example, examples, from table" />
|
||
|
<meta name="keywords" content="data manipulation statement (DML), DELETE statement, description, statements, DELETE, example, examples, from table" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydml.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyrfdeleting.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstdropst.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstdelst.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rbafydelete" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Remove rows from a table using the DELETE statement</title>
|
||
|
</head>
|
||
|
<body id="rbafydelete"><a name="rbafydelete"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Remove rows from a table using the DELETE statement</h1>
|
||
|
<div><p>To remove rows from a table, use the DELETE statement. </p>
|
||
|
<p>When you DELETE a row, you remove the entire row. DELETE does not remove
|
||
|
specific columns from the row. The result of the DELETE statement is the removal
|
||
|
of zero or more rows of a table (depending on how many rows satisfy the search
|
||
|
condition specified in the WHERE clause). If you omit the WHERE clause from
|
||
|
a DELETE statement, SQL removes all the rows of the table. The DELETE statement
|
||
|
looks like this: </p>
|
||
|
<pre> <strong>DELETE FROM</strong> table-name
|
||
|
<strong>WHERE</strong> search-condition ...</pre>
|
||
|
<p>For example, suppose department D11 was moved to another place. You want
|
||
|
to delete each row in the CORPDATA.EMPLOYEE table with a WORKDEPT value of
|
||
|
D11 as follows: </p>
|
||
|
<pre> <strong>DELETE FROM</strong> CORPDATA.EMPLOYEE
|
||
|
<strong>WHERE</strong> WORKDEPT = 'D11'</pre>
|
||
|
<p>The WHERE clause tells SQL which rows you want to delete from the table.
|
||
|
SQL deletes all the rows that satisfy the search condition from the base table.
|
||
|
Deleting rows from a view deletes the rows from the base table. You can omit
|
||
|
the WHERE clause, but it is best to include one, because a DELETE statement
|
||
|
without a WHERE clause deletes all the rows from the table or view. To delete
|
||
|
a table definition as well as the table contents, issue the DROP statement. </p>
|
||
|
<p>If SQL finds an error while running your DELETE statement, it stops deleting
|
||
|
data and returns a negative SQLCODE. If you specify COMMIT(*ALL), COMMIT(*CS),
|
||
|
COMMIT(*CHG), or COMMIT(*RR), no rows in the table are deleted (rows already
|
||
|
deleted by this statement, if any, are restored to their previous values).
|
||
|
If COMMIT(*NONE) is specified, any rows already deleted are <em>not</em> restored
|
||
|
to their previous values.</p>
|
||
|
<div class="p">If SQL cannot find any rows that satisfy the search condition, an SQLCODE
|
||
|
of +100 is returned. <div class="note"><span class="notetitle">Note:</span> The DELETE statement may have deleted more than
|
||
|
one row. The number of rows deleted is reflected in SQLERRD(3) of the SQLCA.
|
||
|
This value is also available from the ROW_COUNT diagnostics item in the GET
|
||
|
DIAGNOSTICS statement.</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="rbafyrfdeleting.htm">Delete from tables with referential constraints</a></strong><br />
|
||
|
If a table has a primary key but no dependents, the DELETE statement operates as it does without referential constraints. The same is true if a table has only foreign keys, but no primary key. If a table has a primary key and dependent tables, DELETE deletes or updates rows according to the delete rules specified.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafydml.htm" title="Data manipulation language (DML) describes the portion of SQL that allows you to manipulate or control your data.">Data manipulation language</a></div>
|
||
|
</div>
|
||
|
<div class="relinfo"><strong>Related information</strong><br />
|
||
|
<div><a href="../db2/rbafzmstdropst.htm">DROP statement</a></div>
|
||
|
<div><a href="../db2/rbafzmstdelst.htm">DELETE statement</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|