Excerpt fro pgsql 8.4 docs : " [...]a column constraint is only a notational convenience for use when the constraint only affects one column." How is this valid sql then?
DROP TABLE IF EXISTS test;
CREATE TABLE test(
id integer CONSTRAINT PK_test PRIMARY KEY CONSTRAINT nenull NOT NULL CHECK (id3>=id2)
--the check constraint affects two columns none of which is id
,id2 integer
, id3 integer
);
the excerpt seems to apply only to PRIMARY KEY and FOREIGN KEY constraints which should only affect the column on the same line where the constraints are declarated as Catcall has stated
Constraints are the rules enforced on data columns on table. These are used to prevent invalid data from being entered into the database. This ensures the accuracy and reliability of the data in the database. Constraints could be column level or table level.
What is the difference between a column constraint and a table constraint? A column constraint applies to a single column; a table restraint may apply to many columns.
Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table. If there is any violation between the constraint and the data action, the action is aborted. Constraints can be column level or table level.
Column constraints are restrictions on the data that can be inserted into a given column.
Elsewhere in the docs . . .
We say that the first two constraints are column constraints, whereas the third one is a table constraint because it is written separately from any one column definition. Column constraints can also be written as table constraints, while the reverse is not necessarily possible, since a column constraint is supposed to refer to only the column it is attached to. (PostgreSQL doesn't enforce that rule, but you should follow it if you want your table definitions to work with other database systems.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With