File: indexes-unique.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (47 lines) | stat: -rw-r--r-- 2,619 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>11.5.Unique Indexes</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="indexes.html" title="Chapter11.Indexes">
<link rel="prev" href="indexes-bitmap-scans.html" title="11.4.Combining Multiple Indexes">
<link rel="next" href="indexes-expressional.html" title="11.6.Indexes on Expressions">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="indexes-unique"></a>11.5.Unique Indexes</h2></div></div></div>
<a name="id628711"></a><p>   Indexes may also be used to enforce uniqueness of a column's value,
   or the uniqueness of the combined values of more than one column.
</p>
<pre class="synopsis">CREATE UNIQUE INDEX <em class="replaceable"><code>name</code></em> ON <em class="replaceable"><code>table</code></em> (<em class="replaceable"><code>column</code></em> [<span class="optional">, ...</span>]);</pre>
<p>
   Currently, only B-tree indexes can be declared unique.
  </p>
<p>   When an index is declared unique, multiple table rows with equal
   indexed values will not be allowed.  Null values are not considered
   equal.  A multicolumn unique index will only reject cases where all
   of the indexed columns are equal in two rows.
  </p>
<p>   <span class="productname">PostgreSQL</span> automatically creates a unique
   index when a unique constraint or a primary key is defined for a table.
   The index covers the columns that make up the primary key or unique 
   columns (a multicolumn index, if appropriate), and is the mechanism
   that enforces the constraint.
  </p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>    The preferred way to add a unique constraint to a table is
    <code class="literal">ALTER TABLE ... ADD CONSTRAINT</code>.  The use of
    indexes to enforce unique constraints could be considered an
    implementation detail that should not be accessed directly.
    One should, however, be aware that there's no need to manually
    create indexes on unique columns; doing so would just duplicate
    the automatically-created index.
   </p>
</div>
</div></body>
</html>