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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:05:31+00:00 2026-05-31T05:05:31+00:00

I need to store data related to items where there will be various different

  • 0

I need to store data related to “items” where there will be various different item types, all with common attributes, and then each type with its own additional attributes. I expect this is a common requirement; what’s the best-practices solution? We’re using SQL Server.

Let’s use a made-up example:

Vehicle has

  • Price
  • Make
  • Model
  • Owner

(In our real data, there will be 10-15 common columns.)

Car is a Vehicle plus:

  • Style (sedan, sports, etc.)
  • Color
  • EngineSize

Boat is a Vehicle plus:

  • Displacement
  • PortOfOrigin

…etc. for several types of things. In our real data, each specialized type will typically add 2-5 columns; there will be 5 types to start with. We’ll be adding types over time, but probably only 3 or 4 more in total (if that). Adding types requires development, so it’s not like “tags” which can be added willy-nilly by end users. We assume adding a type will require changes to the DB and client tiers, and probably the mid-tier as well. That’s totally fine.

We will do lots of queries across all of the items (vehicles, in the example above); we only worry about the details of a specific item type (Car, Boat) rarely.

I see four ways to store this data:

  1. Separate tables for Cars, Boats, etc., with duplicated columns.
  2. One table with the Vehicle data, a table for the additional Car data, and a table for the additional Boat data.
  3. One table of items, a separate table of item attributes with a row per additional attribute. E.g., a soft schema for the details.
  4. One table with generic columns given meaning only by non-DB code.

Looking at each:

  1. Separate tables for Cars, Boats, etc., with duplicated columns. E.g., roughly:

    CREATE TABLE [Cars] (
        [Id] IDENTITY PRIMARY KEY,
        [Price] DECIMAL (19, 4),
        [Make] NVARCHAR(200),
        [Model] NVARCHAR(200),
        [Owner] INT,
        [Id] INT PRIMARY KEY,
        [Style] NVARCHAR(200),
        [Color] NVARCHAR(200),
        [EngineSize] DECIMAL(19, 2)
    )
    CREATE TABLE [Boats] (
        [Id] IDENTITY PRIMARY KEY,
        [Price] DECIMAL (19, 4),
        [Make] NVARCHAR(200),
        [Model] NVARCHAR(200),
        [Owner] INT,
        [Id] INT PRIMARY KEY,
        [Displacement] DECIMAL(19, 4),
        [PortOfOrigin] NVARCHAR(200)
    )
    

    Simple enough, Cars go in Cars and Boats go in Boats. If we add more vehicle types, we add a table. If we add another common column, we have to go back and add it to all the vehicle tables. Reporting against vehicles in general can be done against a union view of all of the tables (being careful about the Id column).

  2. One table with the Vehicle data, a table for the additional Car data, and a table for the additional Boat data. E.g., roughly:

    CREATE TABLE [Vehicles] (
        [Id] IDENTITY PRIMARY KEY,
        [Price] DECIMAL (19, 4),
        [Make] NVARCHAR(200),
        [Model] NVARCHAR(200),
        [Owner] INT,
        [Type] INT        -- A type ID, e.g. "Car" vs. "Boat"
    )
    CREATE TABLE [Cars] (
        [Id] INT PRIMARY KEY,
        [Style] NVARCHAR(200),
        [Color] NVARCHAR(200),
        [EngineSize] DECIMAL(19, 2)
    )
    CREATE TABLE [Boats] (
        [Id] INT PRIMARY KEY,
        [Displacement] DECIMAL(19, 4),
        [PortOfOrigin] NVARCHAR(200)
    )
    

    So every Car would have one row in Vehicles and one linked row in Cars. Every Boat would have one row in Vehicles and one linked row in Boats. If we add more vehicle types, we add a table. Reporting against vehicles in general can be done against just the Vehicle table. When retrieve details of a specific Car or Boat, we use a join.

  3. One table of items, a separate table of item attributes with a row per additional attribute. E.g., a soft schema for the details. E.g., roughly:

    CREATE TABLE [Vehicles] (
        [Id] IDENTITY PRIMARY KEY,
        [Price] DECIMAL (19, 4),
        [Make] NVARCHAR(200),
        [Model] NVARCHAR(200),
        [Owner] INT,
        [Type] INT
    )
    CREATE TABLE [VehicleDetails] (
        [VehicleId] INT,
        [Name] NVARCHAR(200),
        [Value] NVARCHAR(MAX)
    )
    

    So every Car gets one row in Vehicles and three rows in VehicleDetails (one each for “Style”, “Color”, and “EngineSize”). Reporting is largely done against the Vehicle table. Reporting on details starts getting messy fast. Soft schemas have their place, mostly around user-defined data, but I’m assuming this wouldn’t be a good choice here.

  4. One table with generic columns given meaning only by non-DB code:

    CREATE TABLE [Vehicles] (
        [Id] IDENTITY PRIMARY KEY,
        [Price] DECIMAL (19, 4),
        [Make] NVARCHAR(200),
        [Model] NVARCHAR(200),
        [Owner] INT,
        [Type] INT,
        [Detail01] NVARCHAR(MAX),
        [Detail02] NVARCHAR(MAX),
        [Detail03] NVARCHAR(MAX),
        [Detail04] NVARCHAR(MAX),
        [Detail05] NVARCHAR(MAX),
        [Detail06] NVARCHAR(MAX),
        [Detail07] NVARCHAR(MAX),
        [Detail08] NVARCHAR(MAX),
        [Detail09] NVARCHAR(MAX),
        [Detail10] NVARCHAR(MAX)
    )
    

    So Car data would assign Style to Detail01, Color to Detail02, and EngineSize to Detail03; for Boats, we’d put Displacement in Detail01 and PortOfOrigin in Detail02. Similarly, there may be a place for this with end-user defined schemas, but I’m guessing this wouldn’t be a good answer when you can control the DB structure.

  • 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-31T05:05:33+00:00Added an answer on May 31, 2026 at 5:05 am

    It depends.

    Approach 1 is best for situations where most attributes will be common to most types.

    Approach 2 is best for situations where few attributes will be common to most types.

    Approach 3 is essentially approach 1, with an Entity-Attribute-Value approach to handling type-specific attributes. This approach is best for situations where most attributes will be common to most types, and it is difficult to anticipate what additional attributes will be required – it is quite common in situations that require user-created fields.

    Approach 4 is not a good idea in any situation – it removes semantic content from the metadata layer into the code layer, while retaining the inflexibility of Approach 1.

    There is also another possible approach – a pure Entity-Attribute-Value approach (essentially a blend of approaches 3 and 4). This is generally regarded as an anti-pattern, due to the complexity and poor performance produced when implemented on a RDBMS. However, there are some situations where it is the only approach possible – primarily, where the entity relationships are not known in advance.

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

Sidebar

Related Questions

I'm writing a program in C# that will need to store a few Data
I need to store some session related data for a user. This data does
I need a system that will allow users to modify data that is related
I need to pass data related to processing an item in between item processors,
I need to store some data in a Django model. These data are not
I usually use C++ stdlib map whenever I need to store some data associated
I need to store some sensitive data by encrypting it with atleast 128 bit
I need to store a tree data structure in my database, for which I
I need to store large amounts of metering data in a database. A record
I need to store of 100-200 data in mysql, the data which would be

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.