SQLite Forum

Constraint Name
Login

Constraint Name

(1) By Daril (PetrDaricek) on 2020-06-09 11:39:37 [link] [source]

Hello,

I see documentation of SQLite and I wonder what is the purpose of Constraint Name, especially constraint name of Generated Column. Has it any practical or future usage. I don't see any reason why I should use it.

Thank you Petr

(2.1) By David Jones (vman59) on 2020-06-09 12:23:43 edited from 2.0 in reply to 1 [source]

The error message for a constraint violation includes the name of the constraint.

(3) By Keith Medcalf (kmedcalf) on 2020-06-09 12:33:52 in reply to 1 [link] [source]

A constraint name is used to give a name to a constraint. Sometimes when a constraint is violated its name is reported to help you determine the error of your ways.

Just because you can do a thing, does not mean you must do a thing, nor does it mean that it would be useful to do a thing.

It might not be useful to have a constraint name on a default, not null, or collate either. Yet there you have it, you can assign a constraint name to these things also if you wish.

The fact of the matter is that they are constraints on the value of a column and therefore may be given a name. The fact that you can give column constrains a name if you choose to do so is quite independent of the utility of doing so.

Some people are in love with giving everything a label/name, just as some people are in love with using ill-conceived character sequences in identifiers, and still other are in love with using identifier quotes even when not needed; some are in love with extraneous parenthesis, and some in love with making everything a left join when they mean equi-join; there are even some people are in love with prefixing column names with the name of the table containing the column despite the fact that the scope of a column name is the table in which it is declared.

There is no explanation for why people do the things they do. It just is.

However, on the other hand, the very definition of column constraint as a generic thing permits them to have names. Dividing the class column constraint into two classes simply to avoid the optional capability that a column constraint can be given a name increases complexity yet provides zero additional capability since one can already choose to not give a column constraint a name.

(4) By Clemens Ladisch (cladisch) on 2020-06-09 12:36:38 in reply to 1 [link] [source]

For CHECK constraints, SQLite shows the name in error messages. For other constraints, the SQL standard allows them.

I guess treating non-constraint column properties as constraints makes the SQLite grammar simpler, although it is not allowed by the standard:

<column definition> ::=
		<column name> [ <data type> | <domain name> ] [ <reference scope check> ]
		[ <default clause> | <identity column specification> | <generation clause> ]
		[ <column constraint definition>... ] [ <collate clause> ]