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

  • Home
  • SEARCH
  • 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 4626904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:29:20+00:00 2026-05-22T03:29:20+00:00

Using the following table layout: TABLE Something ( SomethingId Name DateCreated IsObsolete (‘Y’,’N’) PRIMARY

  • 0

Using the following table layout:

TABLE Something
(
    SomethingId             
    Name      
    DateCreated
    IsObsolete ('Y','N')       
    PRIMARY KEY (SomethingId)
    Foreign Key (SomethingTypeCode)
;


TABLE SomethingType
(
    SomethingTypeCode ('1','2','3')             
    Description             
    PRIMARY KEY (SomethingTypeCode)
);

With a PHP/MySQL setup is there some way that I can restrict through a constraint or index that for each SomethingTypeCode (1, 2, 3) identified in the Something table, there can only be one IsObsolete = N associated with it?

I hope that explains what I am trying to accomplish. I just don’t know what to look into to resolve this. I want data integrity to be maintained as much as possible in the db itself and then extend that to the PHP.


EDIT:

In response to the confusion I am getting with VoteyDisciple answer.

EmailTypeCode: P = Personal, B = Business, S = School

Here is my design:

enter image description here

This will allow a Person to have more then one type of email in a given typecode (i.e. 2 business emails) and avoid duplication in the db and not require any nulls. Since i am only concerned with having one active email in each category (the one that will be used by the system) that is where the IsObsolete comes into play. I can keep the history, avoid duplication, avoid nulls, and ensure unique email addresses entered into the system here.

Of course this also brings about my problem as stated in original question.

VoteyDisciple’s approach

VoteyDisciple please let me know if I depicted it wrong (or correct).

enter image description here

“If there can be only one for a given type” – Only one active not a time, not only one in the system.

“Now ActiveId can be NULL” – I have emphasized I do not want NULLs

“or it can point to a specific Something record.” The type defines the record.

On top of my responses above this seems to add undo complexity into any queries. My responses are based on my understanding of what you have presented. We are either not understanding each other or it is only on my end. I appreciate your input, but as presented I don’t see it as a viable solution.

  • 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-22T03:29:21+00:00Added an answer on May 22, 2026 at 3:29 am

    You should be able to deal with this in a MySQL trigger:

    DELIMITER $$
    CREATE TRIGGER before_something_update 
    BEFORE UPDATE ON Something
    FOR EACH ROW BEGIN
       IF NEW.IsObsolete = 'N' THEN
          UPDATE Something SET IsObsolete = 'Y' WHERE SomethingId != NEW.SomethingId AND SomethingTypeID = NEW.SomethingTypeId;
       END IF; 
    DELIMITER ;
    

    And something similar on insert.
    The trigger will check to see if you’re trying to set IsObselete to N and if you are then update all the rows that have the same type that are not the current row and set them to Y.

    You may get into issues with deadlocks if you’re using InnoDB but I don’t think you’ll have an issue with MyISAM.

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

Sidebar

Related Questions

Table Layout: TABLE ORDER: id localizedInfoId Table OrderLocalizedInfo: id localizedInfoId name With the following
Given an Oracle table created using the following: CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME
I can drop a table if it exists using the following code but do
I have the following Hibernate Mapping, which has to be mapped using the Table
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
I am using table layout to display data, but i want it to behave
I've reduced my problem (table layout algorithm) to the following problem: Imagine I have
Suppose I have following table in my database: Tbl_Persons: Id Country Name 1 Australia
I want to check SID and current database name. I am using following query
I am using following PHP code to connect to MS Access database: $odb_conn =

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.