@@ -1233,16 +1233,32 @@ CREATE TABLE order_items (
12331233 </para>
12341234
12351235 <para>
1236- Restricting and cascading deletes are the two most common options.
1237- <literal>RESTRICT</literal> prevents deletion of a
1238- referenced row. <literal>NO ACTION</literal> means that if any
1239- referencing rows still exist when the constraint is checked, an error
1240- is raised; this is the default behavior if you do not specify anything.
1241- (The essential difference between these two choices is that
1242- <literal>NO ACTION</literal> allows the check to be deferred until
1243- later in the transaction, whereas <literal>RESTRICT</literal> does not.)
1236+ The default <literal>ON DELETE</literal> action is <literal>ON DELETE NO
1237+ ACTION</literal>; this does not need to be specified. This means that the
1238+ deletion in the referenced table is allowed to proceed. But the
1239+ foreign-key constraint is still required to be satisfied, so this
1240+ operation will usually result in an error. But checking of foreign-key
1241+ constraints can also be deferred to later in the transaction (not covered
1242+ in this chapter). In that case, the <literal>NO ACTION</literal> setting
1243+ would allow other commands to <quote>fix</quote> the situation before the
1244+ constraint is checked, for example by inserting another suitable row into
1245+ the referenced table or by deleting the now-dangling rows from the
1246+ referencing table.
1247+ </para>
1248+
1249+ <para>
1250+ <literal>RESTRICT</literal> is a stricter setting than <literal>NO
1251+ ACTION</literal>. It prevents deletion of a referenced row.
1252+ <literal>RESTRICT</literal> does not allow the check to be deferred until
1253+ later in the transaction.
1254+ </para>
1255+
1256+ <para>
12441257 <literal>CASCADE</literal> specifies that when a referenced row is deleted,
12451258 row(s) referencing it should be automatically deleted as well.
1259+ </para>
1260+
1261+ <para>
12461262 There are two other options:
12471263 <literal>SET NULL</literal> and <literal>SET DEFAULT</literal>.
12481264 These cause the referencing column(s) in the referencing row(s)
@@ -1312,6 +1328,15 @@ CREATE TABLE posts (
13121328 NULL</literal> and <literal>SET DEFAULT</literal>.
13131329 In this case, <literal>CASCADE</literal> means that the updated values of the
13141330 referenced column(s) should be copied into the referencing row(s).
1331+ There is also a noticeable difference between <literal>ON UPDATE NO
1332+ ACTION</literal> (the default) and <literal>NO UPDATE RESTRICT</literal>.
1333+ The former will allow the update to proceed and the foreign-key constraint
1334+ will be checked against the state after the update. The latter will
1335+ prevent the update to run even if the state after the update would still
1336+ satisfy the constraint. This prevents updating a referenced row to a
1337+ value that is distinct but compares as equal (for example, a character
1338+ string with a different case variant, if a character string type with a
1339+ case-insensitive collation is used).
13151340 </para>
13161341
13171342 <para>
0 commit comments