73 lines
3.9 KiB
HTML
73 lines
3.9 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="copyright" content="(C) Copyright IBM Corporation 2005" />
|
|
<meta name="DC.rights.owner" content="(C) Copyright IBM Corporation 2005" />
|
|
<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="task" />
|
|
<meta name="DC.Title" content="Create a view on a single table" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzatcviewsql.htm" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="crtviewsql" />
|
|
<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>Create a view on a single table</title>
|
|
</head>
|
|
<body id="crtviewsql"><a name="crtviewsql"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Create a view on a single table</h1>
|
|
<div><div class="section">The following example procedure shows how to create a view on a single
|
|
table. The view is built on the INVENTORY_LIST table. The table has six columns,
|
|
but the view uses only three of the columns: ITEM_NUMBER, LAST_ORDER_DATE,
|
|
and QUANTITY_ON_HAND. The order of the columns in the SELECT clause is the
|
|
order in which they appear in the view. The view contains only
|
|
the rows for items that were ordered in the last two weeks. The CREATE VIEW
|
|
statement looks like this:</div>
|
|
<ol><li class="stepexpand"><span>Use the following command to create the view:</span> <pre><strong>CREATE VIEW</strong> SAMPLECOLL.RECENT_ORDERS AS
|
|
<strong>SELECT</strong> ITEM_NUMBER, LAST_ORDER_DATE, QUANTITY_ON_HAND
|
|
<strong>FROM</strong> SAMPLECOLL.INVENTORY_LIST
|
|
<strong>WHERE</strong> LAST_ORDER_DATE > CURRENT DATE - 14 DAYS</pre>
|
|
<p>In
|
|
the preceding example, the columns in the view have the same name as the columns
|
|
in the table because no column list follows the view name. The schema that
|
|
the view is created into does not need to be the same schema as the table
|
|
it is built over. Any schema or library can be used.</p>
|
|
</li>
|
|
<li class="stepexpand"><span>Run this statement:</span> <pre><strong>SELECT *FROM</strong> SAMPLECOLL.RECENT_ORDERS</pre>
|
|
</li>
|
|
</ol>
|
|
<div class="section">The result looks like this:<div class="p"><pre class="screen"> Display Data
|
|
Data width . . . . . . : 26
|
|
Position to line . . . . . Shift to column . . . . . .
|
|
....+....1....+....2....+.
|
|
ITEM LAST QUANTITY
|
|
NUMBER ORDER ON
|
|
DATE HAND
|
|
303476 05/30/94 100
|
|
******** End of data ********
|
|
Bottom
|
|
F3=Exit F12=Cancel F19=Left F20=Right F21=Split</pre>
|
|
</div>
|
|
<p>The
|
|
only row selected by the view is the row that you updated to have the current
|
|
date. All other dates in our table still have the null value so they are not
|
|
returned.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzatcviewsql.htm">Create and use a view</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |