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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:25:11+00:00 2026-05-30T16:25:11+00:00

I have the following SQL design issue. The code below might look a little

  • 0

I have the following SQL design issue. The code below might look a little much but basically I have a table of cars and another table of attributes the car could have. This makes complete sense to me to structure a table of attributes for an object using a linking table, #CarSupportedAtttibutes. Recently I’ve been tasked with doing something similar but use one table that has each of the Attributes as columns making it “flat”. Similar to below:

[CarId][Name][Manual Transmission][Sunroof][Automatic Transmission][AWD]

I am told doing so it will boost the speed of my queries, but its starting to turn into a nightmare. In C# I have enumerated values for each of the car’s attributes, 1 = Manual Transmission, so using the non “flat” version I am able to pull off a query pretty quickly as the SQL code below shows. Since I am being pushed to making the table flat for speed the only way I can think of is to take the enumerated value and build it into the where clause, using a case statement for every 1,2,3 and selecting off a column name.

To me it just makes more sense to organize the data like below. Like what if a new attribute about a car is needed, say “HEMI Engine”. Not all cars are going to have this, in fact its going to be a rare case. But The way I am told to design is to keep the table “flat”, so now I would be adding a Column called “Hemi Engine” to my table, instead of adding a row in my CarAttributes, and then only adding rows for the cars that have that as true.

Below is a snippet of the way I currently see approaching this problem, as opposed to doing a “flat” table (table with mostly columns of bits).

Question: What design makes more sense? Which is more maintainable? Am I completely crazy for thinking below is a better approach, and why?

CREATE TABLE #Car
(
    CarId INT,
    Name VARCHAR(250)
)

INSERT INTO #Car VALUES (1, 'Fusion')
INSERT INTO #Car VALUES (2, 'Focus')


CREATE TABLE #CarAttributes
(
    AttributeId INT,
    Name VARCHAR(250)
)

INSERT INTO #CarAttributes VALUES (1, 'Manual Transmission')
INSERT INTO #CarAttributes VALUES (2, 'SunRoof')


SELECT * FROM #CarAttributes

CREATE TABLE #CarSupportedAttributes
(
    AttributeId INT,
    CarId INT
)
INSERT INTO #CarSupportedAttributes VALUES (1,2)


--Determine if A Focus has a manual transmission
SELECT * FROM #Car c
INNER JOIN #CarSupportedAttributes csa
    ON csa.CarId = c.CarId
INNER JOIN #CarAttributes ca
    ON ca.AttributeId = csa.AttributeId 
WHERE c.Name = 'Focus'
    AND ca.AttributeId = 1
  • 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-30T16:25:12+00:00Added an answer on May 30, 2026 at 4:25 pm

    Your approach is known as Entity-Attribute-Value, or EAV (yours is slightly modified, since in your model the presence of the attribute on the entity is the value, but the concept is the same).

    EAV is usually considered an anti-pattern, but it can be appropriate in some cases. Basically, if either…

    • Your list of attributes is large and any given entity (car) will have only a small percentage of the total attributes
    • Your list of attributes is subject to frequent user change and they represent only data and not anything structural about the entity

    Then EAV can be an appropriate choice. I can’t answer either of those questions for you (though I have my suspicions), but it does seem like it might be appropriate in your case.

    The other option, which is likely what most 6NF proponents would suggest, would be to have a table per attribute, like CarSunroof or CarManualTransmission. This would solve the first issue and the requirement of changing a table’s definition whenever a new attribute is added, but would not address the issue of the user being able to change it.

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

Sidebar

Related Questions

I have an SQL table with the following design: TableSchedule: Id Description ImportedDate I
I have the following sql query for transforming data but is it possible to
I have the following SQL table - Date StoreNo Sales 23/4 34 4323.00 23/4
I have the following SQL table: A|B --- w|x x|w y|z z|y Can I
I have an SQL table with the following structure: Code1 - int Code2 -
I'm facing the following design issue: There will be several prepared SQL statements where
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following SQL Statement. I need to select the latest record for

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.