Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Multiple unique columns sqlite3

I'm working on a web application which has to do with restaurant menu. I'm using node for back-end and sqlite3 for database system. In my 'items' table i have a field called barcode which is of-course unique, but the user can input some "extra barcodes". What i need is a way to make barcode field and extra_barcodes fields unique between each others.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

To prevent the same value occurring in multiple columns, you cannot use CHECK constraints (because subqueries are not allowed there), so you have to use triggers:

CREATE TRIGGER barcode_unique_insert
AFTER INSERT ON items
BEGIN
    SELECT RAISE(FAIL, "duplicate barcode")
    FROM items
    WHERE extra_barcode  = NEW.barcode
       OR extra2_barcode = NEW.barcode;
END;

It might be a better idea to store barcodes in a separate table with an 1:N relationship.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!