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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:55:58+00:00 2026-05-20T17:55:58+00:00

Hello, I’m currently trying to apply the most efficient way to store an extend

  • 0

Hello,
I’m currently trying to apply the most efficient way to store an “extend” relationship between entities in a relational database.

For the sake of example, lets say we have the following simplified entities:

  • User
  • Student (extends User)
  • Teacher (extends User)

User contains attributes which apply to both Student and Teacher. Both Student and Teacher contain custom attributes which are unique to them.

The first thing that comes to mind is to create a single table with columns for all singular data (i.e. except one-to-many fields):

User
-------------
User ID
First name
Last name
Student class
Teacher office no.
Teacher description
...

This however won’t be very efficient from a storage perspective, because:

  • the majority of rows will contain students, with a small number of teachers
  • teachers will have much more unique columns, which would waste space in students’ rows

It would be more efficient to replicate relationships between the entities:

User
-------------
User ID
First name
Last name
...


Student
-------------
User ID
Student class
...


Teacher
-------------
User ID
Teacher office no.
Teacher description
...

So my questions are:

  1. Is the above concern taking it too far, i.e. should we leave storage efficiency to the database engine?
  2. Is splitting the entities into 3 tables still OK in terms of normalization?
  3. If it’s not a good approach, how would you recommend to treat “extend” relationships in a relational database?

Thank you.

  • 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-20T17:55:59+00:00Added an answer on May 20, 2026 at 5:55 pm

    If a user can’t be both a teacher and a student, then you’re looking at a straightforward supertype/subtype problem. (I’m using supertype and subtype in their relational database design sense, not in their object-oriented programming sense.) You’re right to store in “students” only those attributes that describe students, and to store in “teachers” only those attributes that describe teachers.

    -- Supertype: users
    create table users (
      user_id integer not null unique,
      user_type char(1) not null 
        check (user_type in ('T', 'S')),
      -- other user columns
      primary key (user_id, user_type)
    );
    
    -- Subtype: students
    create table students_st (
      user_id integer not null,
      user_type char(1) not null default 'S'
        check (user_type = 'S'),
      locker_num integer not null unique 
        check (locker_num > 0),
      -- other student columns
      primary key (user_id, user_type),
      foreign key (user_id, user_type) 
        references users (user_id, user_type) 
        on delete cascade
    );
    
    -- Subtype: teachers
    create table teachers_st (
      user_id integer not null,
      user_type char(1) not null default 'T'
        check (user_type = 'T'),
      office_num char(4),
      -- other teacher columns
      primary key (user_id, user_type),
      foreign key (user_id, user_type) 
        references users (user_id, user_type) 
        on delete cascade
    );
    
    create view teachers as 
    select u.user_id,
           u.user_type,
           -- other user columns
           t.office_num
           -- other teacher columns
    from users u
    inner join teachers_st t on (u.user_id = t.user_id);
    
    create view students as 
    select u.user_id,
           u.user_type,
           -- other user columns
           s.locker_num
           -- other student columns
    from users u
    inner join students_st s on (u.user_id = s.user_id);
    

    At this point, you’d also do whatever your dbms requires to make these two views updatable—triggers, rules, whatever. Application code inserts, updates, and deletes from the views, not from the base tables.

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

Sidebar

Related Questions

Hello everyone i am trying to format the input number range with php number_format
hello friends i am trying to get a list of user id and want
Hello Guys I am trying to figure out why i am gettings this error
Hello StackOverflow, I'd like to know if there is way to trigger an event
Hello All I am trying to flatten a list in Ocaml. I am a
Hello There, I am new to phonegap.I am trying to record a audio clip
. Hello, I am trying to add a UIButton and other items to my
. Hello, I am trying to make a Custom Segue for my storyboard. Now
Hello i am trying to check to see if there is a row in
Hello I need some help to set up the LDAP user store for WSO2

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.