mysql - Postgres, Create uniqueness of values between 2 columns -
and thank ahead of time able help. have table shown below.
table invoice
id| delivery_statement_id | supply_statement_id
_ | 1 |2
_ | 3 |4
_ | 2 | 4 <-should not pass db because id 2 used in first row.
i want make sure unique ids exists between 2 columns throughout entire database
if statement_id 1 has been used can never used again delivery, or supply statement. please help, when search issue keep getting index multiple columns solves issues of row combinations.
thank you
my understanding is, have table of following structure:
"invoice" ( id (primary key), delivery_statement_id, supply_statement_id )
judging names of colums, "delivery_statement_id" , "supply_statement_id" foreign keys same, external table... let's say, refer "statement"
"invoice" ( id (primary key), delivery_statement_id -> statement(id), supply_statement_id -> statement(id) )
if have table "statement" , want avoid having multiple references "delivery_statement_id" , "supply_statement_id" - advise add "invoice_id" column "statement" table:
"statement" ( id (primary key), /** other columns **/ invoice_id (nullable, unique constraint) -> invoice(id) )
so first create rows in "statement" without reference invoice set delivery_statement_id , supply_statement_id , after setting each value must "register" in "statement" table... can implemented trigger, attached "invoice" table
Comments
Post a Comment