Answer the question
In order to leave comments, you need to log in
Is it possible to set a unique field in two tables?
Good afternoon!
There are 2 tables:
Answer the question
In order to leave comments, you need to log in
Slightly strange structure.
If they must be unique, then make one of the columns a FOREIGN KEY and make both columns UNIQUE.
Or make such a structure so that both columns are in the same table and make the index UNIQUE composite.
If you want a unique key for 2 tables (which is rather strange), then you can simply put a constraint on the primary key. For example like this:
CREATE TABLE `table_1` (
`id` INT CHECK(id BETWEEN 10000 AND 49999)
);
CREATE TABLE `table_2` (
`id` INT CHECK(id BETWEEN 50000 AND 99999)
);
But in PostgreSQL, this is easy to do through sequences. And so everyone is right, it is better to redo the base itself. She is clearly not good.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question