From a PostgreSQL article on foreign keys constraints at https://www.postgresql.org/docs/current/ddl-constraints.html:
Say you have the product table :
CREATE TABLE products ( product_no integer PRIMARY KEY, name text, price numeric );Let's also assume you have a table storing orders of those products. We want to ensure that the orders table only contains orders of products that actually exist. So we define a foreign key constraint in the orders table that references the products table:
CREATE TABLE orders ( order_id integer PRIMARY KEY, product_no integer REFERENCES products (product_no), quantity integer );Now it is impossible to create orders with non-NULL product_no entries that do not appear in the products table.
Is this a 0-to-many relationship?
How can I set a one-to-many relationship?
By doing this?
CREATE TABLE orders (
order_id integer PRIMARY KEY,
product_no integer REFERENCES products (product_no) NOT NULL,
quantity integer
);
If that is the case, why does pgadmin4 generate this crow foot notation that denotes a zero-to-many when I configure the table as above?





No, it doesn't. Do not confuse the cardinality (which is directional) with the type of the relation. The circle denotes the lower bound of the
orderscardinality (and may be omitted) - see "many" vs "zero or many"/"one or many" crowfoot notation? on Software Engineering.Marking the
product_noasNOT NULLonly changes a zero-or-one-to-many relationship into an exactly-one-to-many relationship. Both are commonly referred to as "one-to-many" or "1:N" relationships. This would be expressed as either a dash-dash or dash-circle (or, amiguously, just dash) for the cardinality ofproducts.Now the circle (or dash) on the crow foot is just about the many side (
orders) - is it …-to-zero-or-many or …-to-one-or-many? And in your schema, it is indeed a zero-or-many cardinality, since there can be any number oforders- including0- for aproduct.Notice that an actual
0,1:1,N,1:1..Nor1..N:1..Nrelationship (not…:0,N) is surprisingly hard to represent in SQL since you have a chicken-and-egg problem, see How to Create a real one-to-one relationship in SQL Server or 1:N relationship where N must be at least one entry).