Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:52:37+00:00 2026-06-11T09:52:37+00:00

I apologise for the confusing title but I’m really not sure how to describe

  • 0

I apologise for the confusing title but I’m really not sure how to describe this problem in one sentence.

I have an SQLite database for a generalised tipping competition. For those unfamiliar with the concept, people “tip” who they think will win in each match of each round of a sporting competition, and the person with the most correct tips at the end of the competition wins (the prize may be money, pride, etc). It’s very popular in Australia with the AFL.

The basic structure is that users register as an owner, and they can then create as many competitions as they want, and each competition is linked to them with a foreign key. This is the relevant part of the database schema:

create table owner (
    owner_id INTEGER NOT NULL,
    owner_name VARCHAR NOT NULL,
    owner_nick VARCHAR UNIQUE NOT NULL,
    owner_email VARCHAR NOT NULL,
    owner_password VARCHAR NOT NULL,
    CONSTRAINT owner_pk PRIMARY KEY (owner_id)
);

create table comp (
    comp_id INTEGER NOT NULL,
    comp_owner_id INTEGER NOT NULL,
    comp_name VARCHAR UNIQUE NOT NULL,
    CONSTRAINT comp_pk PRIMARY KEY (comp_id),
    CONSTRAINT comp_owner_fk FOREIGN KEY (comp_owner_id) REFERENCES owner (owner_id) NOT DEFERRABLE
);

The gist of the problem is this: I want to enforce a unique constraint on the comp_name field of the comp table (as shown above) because a single owner shouldn’t have two or more competitions with the same name. However, it is entirely possible that two different owners would want two different competitions with the same name (for example, two offices running tipping competitions for the same sporting league). Is it possible to enforce this using SQL, or do I need to do the enforcement manually elsewhere?

A few notes:

  • I’m using SQLite 3.6.20, which has proper foreign key constraint enforcement
  • The database will never be used in a production level application. It’s a private project.
  • The database is being used in a web-based PHP application.
  • If this cannot be achieved with SQLite, can it be achieved with MySQL?

EDIT: I feel I should point out that I’m aware SQLite has very limited alter table support, and deleting the database and starting over is very much an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:52:39+00:00Added an answer on June 11, 2026 at 9:52 am

    Just create a UNIQUE constraint on those two fields, like so:

    create table comp (
        comp_id INTEGER NOT NULL,
        comp_owner_id INTEGER NOT NULL,
        comp_name VARCHAR NOT NULL,
        CONSTRAINT comp_unq UNIQUE (comp_owner_id, comp_name),
        CONSTRAINT comp_pk PRIMARY KEY (comp_id),
        CONSTRAINT comp_owner_fk FOREIGN KEY (comp_owner_id) REFERENCES owner (owner_id) NOT DEFERRABLE
    );
    

    that should do what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a technical problem and it's really confusing me. I apologise in advance
I apologize for the probably confusing title, but I wasn't quite sure how to
I apologise if this is a bit dim but I want to send something
I apologise if any of this sounds like a broken record but I've trawled
I apologise if this has been asked before but I can't find the info
Apologies for the rather confusing title, I'm finding it rather difficult to phrase this
So I admit the title is a bit, confusing, I apologize cause I have
I have read this , this and this but none of them answers what
I apologize for the somewhat confusing question, I'm not sure how to explain it
This is probably a simple one but I cant get my head around it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.