@@ -1233,16 +1233,32 @@ CREATE TABLE order_items (
1233
1233
</para>
1234
1234
1235
1235
<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>
1244
1257
<literal>CASCADE</literal> specifies that when a referenced row is deleted,
1245
1258
row(s) referencing it should be automatically deleted as well.
1259
+ </para>
1260
+
1261
+ <para>
1246
1262
There are two other options:
1247
1263
<literal>SET NULL</literal> and <literal>SET DEFAULT</literal>.
1248
1264
These cause the referencing column(s) in the referencing row(s)
@@ -1312,6 +1328,15 @@ CREATE TABLE posts (
1312
1328
NULL</literal> and <literal>SET DEFAULT</literal>.
1313
1329
In this case, <literal>CASCADE</literal> means that the updated values of the
1314
1330
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).
1315
1340
</para>
1316
1341
1317
1342
<para>
0 commit comments