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 7640535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:41:39+00:00 2026-05-31T08:41:39+00:00

I am currently developing an architecture in PHP and MySQL and a problem has

  • 0

I am currently developing an architecture in PHP and MySQL and a problem has arisen. I hope this isn’t a ridiculous question but it would be very helpful if there was an answer.

The following is a simplified version of the actual situation. Lets say I have a table with 3 columns representing a number of locations. Each location can potentially be a default location:

location_id int(20), location_name varchar(255), is_default BOOL

Column is_default should only have the values true (1) or false (0). In addition I want to make sure that no more than one row can have is_default set to true. In other words I want to permit a maximum of one true value and a boundless amount of false values:

+-------------+---------------+------------+
| location_id | location_name | is_default |
+-------------+---------------+------------+
|1            |'England'      |1           |
|2            |'America'      |0           |
|3            |'China'        |0           |
|4            |'Russia'       |0           |
+-------------+---------------+------------+

The idea is that only one location can be the default location. Is there any way of expressing this as a data type or column attribute of some sort? Or would I have to enforce the rule in php by simply running two queries so that whenever a location is added whose is_default column = true the old default location’s is_default column = false? It would be great if there was a way to enforce it in MySQL.

It seems like such a simple problem that I thought it would be common but I can’t seem to find an answer anywhere on the internet including the MySQL reference. Unless there is some obvious database design flaw which I have managed to overlook.

  • 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-05-31T08:41:40+00:00Added an answer on May 31, 2026 at 8:41 am

    If you don’t have another table where it belongs, I would create a separate table to specify the default like:

    default_location table
    +------------+
    |location_id |
    +------------+
    |1           |
    +------------+
    

    This way, you can only have one.

    Maybe this belongs in a settings table?

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

Sidebar

Related Questions

Currently developing a PHP framework and have ran into my first problem. I need
I am currently developing an application which by design has a three-tier architecture. It
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am currently developing a program that uses C#'s Dictionary container (specifically, SortedDictionary). This
I currently developing a multi-language interface for a Django project. But when I started
I'm currently developing an ASP.NET Human Resources System. I'm using a layered architecture with
I am developing a high-traffic java web application. Currently I'm defining its architecture. I
For the web application (ASP.NET MVC) I'm currently developing, we have the following architecture
I am currently developing an IVR system, my question is more on a development
Im currently developing my first application in PyQt4, and what i would like to

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.