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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:07:39+00:00 2026-06-05T20:07:39+00:00

Suppose I have a Table1, with three Columns: ID (Primary Key, Identity), A, and

  • 0

Suppose I have a Table1, with three Columns: ID (Primary Key, Identity), A, and B

Now, suppose I have 3 methods, assuming they share nothing in common column-wise:

Method 1: C, D, E

Method 2: F, G, H, I

Method 3: J

I could make one table:
ID, A, B, C, D, E, F, G, H, I, J, M

Where M, is the name of the Method (or a Method ID).

However, if 90% of the time Method 3 is used, there would be many null values.
Is this a problem? If so, is there a better way to set this up?

If I make each method its own table entity, how do I ensure each ID has exactly one method matching for it?

If I keep it as one table, how do I ensure ONLY C, D, E are filled in and F thru J are NULL if M is 1?


OK, seems some people had difficultly thinking abstractly, so I’ll create a random concrete example applying the above:

Suppose I had records of people performing exercises.
Each record would always have an ID (to uniquely identify the event), a TIME_STARTED, and TIME_ENDED.

However, depending on which exercise they did, there would be different attributes needed. Suppose there were only three exercises:

Elliptical: INCLINE, LEVEL, SPEED

Crunches: User_Weight, Reps, Delay, Extra_Weight

Dead Lift: Weight_Lifted

For each ID there could be only one “method”. Applying this, see above questions.

  • 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-05T20:07:40+00:00Added an answer on June 5, 2026 at 8:07 pm

    It sounds like you have a supertype/subtype situation here. In this case, Table1 holds your supertype, and you would want to create a different table to hold each of your subtypes. The PK on these subtype tables would also be an FK to the supertype table. So you would have something like this:

    Supertype_table
    |    ID(PK)   |  A  |  B  |
    
    Subtype1_table
    |  ID(PK&FK)  |  C  |  D  |  E  |
    
    Subtype2_table
    |  ID(PK&FK)  |  F  |  G  |  H  |  I  |
    
    Subtype3_table
    |  ID(PK&FK)  |  J  |
    

    The point of this schema is to make sure that you don’t have a bunch of rows which are mostly nulls. For each method, you would have to write a separate query that would insert/update the appropriate table. With SQL Server, you can make a view which combines all these tables and abstracts away any joins:

    CREATE VIEW MyView
    SELECT Super.ID, Super.A, Super.B, 
    Sub1.C, Sub1.D, Sub1.E, 
    Sub2.F, Sub2.G, Sub2.H, Sub2.I, 
    Sub3.J
    FROM Supertype_table as Super
    LEFT OUTER JOIN Subtype1_table as Sub1 on Super.ID = Sub1.ID
    LEFT OUTER JOIN Subtype2_table as Sub2 on Super.ID = Sub2.ID
    LEFT OUTER JOIN Subtype3_table as Sub3 on Super.ID = Sub3.ID
    

    So then you could just write something like:

    SELECT ID, A, B, J
    FROM MyView
    WHERE J is not null
    

    EDIT : For OP’s comment

    In order to ensure that each ID is in one and only one table, you need some kind of identifier on the supertype table. So if you had a column called TypeID, you would create the function:

    CREATE FUNCTION [dbo].[SubtypeofSuperID](@ID int)
    RETURNS int
    AS
    BEGIN
      DECLARE @TypeID int;
    
        SELECT @TypeID = TypeID 
        FROM Supertype_table
        WHERE ID = @ID
    
      RETURN @TypeID 
    END
    

    Then, using that, you can create a check on each of the subtype tables:

    ALTER TABLE Subtype1_table CONSTRAINT [CK_CorrectSubtype1]
    CHECK ( [dbo].[SubtypeofSuperID]([ID]) = 1 )
    ALTER TABLE Subtype2_table CONSTRAINT [CK_CorrectSubtype2]
    CHECK ( [dbo].[SubtypeofSuperID]([ID]) = 2 )
    ALTER TABLE Subtype3_table CONSTRAINT [CK_CorrectSubtype3]
    CHECK ( [dbo].[SubtypeofSuperID]([ID]) = 3 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a table Item (Id int Primary Key, Number INT) having records
I have three tables (these are the relevant columns): Table1 bookingid, person, role Table2
Suppose I have a table called 'test', into which there are three columns named
Suppose that I have a table with three columns: EventID (PK) TagName TagValue I
Suppose I have these tables create table bug ( id int primary key, name
Suppose I have a table, the first column is an identity. I thought that
Suppose,I have a table with 3 columns and 9 rows and I am using
In MySQL, suppose I have a table called 'data' with columns 'x', 'y', and
I have three tables, 1-Users, 2-Softwares, 3-UserSoftwares. if suppose, Users table having 6 user
Suppose you have a table RULES with 3 columns A, B, and C. As

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.