]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/set_constraints.sgml
Make the SQL command synopses appear less random.
[postgresql] / doc / src / sgml / ref / set_constraints.sgml
1 <!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_constraints.sgml,v 1.9 2003/09/22 00:16:58 petere Exp $ -->
2 <refentry id="SQL-SET-CONSTRAINTS">
3  <refmeta>
4   <refentrytitle id="SQL-SET-CONSTRAINTS-title">SET CONSTRAINTS</refentrytitle>
5   <refmiscinfo>SQL - Language Statements</refmiscinfo>
6  </refmeta>
7
8  <refnamediv>
9   <refname>SET CONSTRAINTS</refname>
10   <refpurpose>set the constraint mode of the current transaction</refpurpose>
11  </refnamediv>
12
13  <indexterm zone="sql-set-constraints">
14   <primary>SET CONSTRAINTS</primary>
15  </indexterm>
16
17  <refsynopsisdiv>
18 <synopsis>
19 SET CONSTRAINTS { ALL | <replaceable class="parameter">name</replaceable> [, ...] } { DEFERRED | IMMEDIATE }
20 </synopsis>
21  </refsynopsisdiv>
22
23  <refsect1>
24   <title>Description</title>
25
26   <para>
27    <command>SET CONSTRAINTS</command> sets the behavior of constraint
28    evaluation in the current transaction. In
29    <literal>IMMEDIATE</literal> mode, constraints are checked at the
30    end of each statement. In <literal>DEFERRED</literal> mode,
31    constraints are not checked until transaction commit.
32   </para>
33
34   <para>
35    When you change the mode of a constraint to be
36    <literal>IMMEDIATE</literal>, the new constraint mode takes effect
37    retroactively: any outstanding data modifications that would have
38    been checked at the end of the transaction (when using
39    <literal>DEFERRED</literal>) are instead checked during the
40    execution of the <command>SET CONSTRAINTS</command> command.
41   </para>
42
43   <para>
44    Upon creation, a constraint is always give one of three
45    characteristics: <literal>INITIALLY DEFERRED</literal>,
46    <literal>INITIALLY IMMEDIATE DEFERRABLE</literal>, or
47    <literal>INITIALLY IMMEDIATE NOT DEFERRABLE</literal>. The third
48    class is not affected by the <command>SET CONSTRAINTS</command>
49    command.
50   </para>
51
52   <para>
53    Currently, only foreign key constraints are affected by this
54    setting. Check and unique constraints are always effectively
55    initially immediate not deferrable.
56   </para>
57  </refsect1>
58
59  <refsect1>
60   <title>Notes</title>
61
62   <para>
63    This command only alters the behavior of constraints within the
64    current transaction. Thus, if you execute this command outside of a
65    transaction block
66    (<command>BEGIN</command>/<command>COMMIT</command> pair), it will
67    not appear to have any effect.  If you wish to change the behavior
68    of a constraint without needing to issue a <command>SET
69    CONSTRAINTS</command> command in every transaction, specify
70    <literal>INITIALLY DEFERRED</literal> or <literal>INITIALLY
71    IMMEDIATE</literal> when you create the constraint.
72   </para>
73  </refsect1>
74
75  <refsect1>
76   <title>Compatibility</title>
77
78   <para>
79    This command complies with the behavior defined in the SQL
80    standard, except for the limitation that, in
81    <productname>PostgreSQL</productname>, it only applies to
82    foreign-key constraints.
83   </para>
84  </refsect1>
85 </refentry>
86
87 <!-- Keep this comment at the end of the file
88 Local variables:
89 mode:sgml
90 sgml-omittag:nil
91 sgml-shorttag:t
92 sgml-minimize-attributes:nil
93 sgml-always-quote-attributes:t
94 sgml-indent-step:1
95 sgml-indent-data:t
96 sgml-parent-document:nil
97 sgml-default-dtd-file:"../reference.ced"
98 sgml-exposed-tags:nil
99 sgml-local-catalogs:("/usr/lib/sgml/catalog")
100 sgml-local-ecat-files:nil
101 End:
102 -->