Answer the question
In order to leave comments, you need to log in
How to set the uniqueness of a field together with a field from another table?
The bottom line is this:
There is a type table:
types
------
id,
name,
prefix
models
--------
id,
name
type_id
items
------
id
model_id
number
SELECT
a.id,
to_char(c.prefix, 'FM0000') || '-' || to_char(a.number, 'FM0000000000') AS code
FROM
items AS a
INNER JOIN models AS b ON a.model_id = b.id
INNER JOIN types AS c ON b.type_id = c.id
Answer the question
In order to leave comments, you need to log in
A universal way for any database and tricks that you come up with is to create a table with a field and an index in the format you need, and fill it with a trigger. If the index of this table fails, the change request of the subordinate tables will also fail, only that the error message will be 'unusual'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question