views:

41

answers:

3

Hi, I have a question regarding DataBase design.

I have a Entity Table named: CARS and I have a Lookup Table named: COLORS

Table CARS has: Id, Name and Table COLORS has just: ColorName

Table COLORS has a short list of colors, instead CARS could have a long list of entities.

CARS has a Primary Key on ID.

My questions are:

  • Adding a Primary Key on Lookup Table COLORS on ColorName, could improve performance?

Table CARS will have a CLUSTERED INDEX on ID.

  • Would you make sense have a CLUSTERED INDEX on CARS on ColorName Thanks gus for your time!
+1  A: 

That's a bit odd. You'd want the COLORS table to have ColorID and ColorName, with the clustered index on ColorID and a foreign key to it on the CARS table. If I'm understanding correctly.

Yellowfog
A: 

1 - If COLORS is a short table, it may improve performance but probably won't really be noticeable.

2 - You can only have one clustered index, and it makes more sense from the limited info you gave for it to be on ID. You will have duplicate entries in ColorName.

Why don't you change colorname to ColorId, add an ID column to Colors and use that as a clustered index/primary key?

JNK
Thanks JNKyle, COLORS should be a Lookup Table and I need have every Colors with a unique value. If I understand well your message, ID Column on COLORS would not be suitable for me.In this case the Clustered Index will be just on ColorName... do you think could be a suitable solution? thanks
GIbboK
If that is the only column in COLORS it would work. It just makes more sense to me to have an ID # associated with the color to save space in the main table. Instead of a 12 bit or whatever length color name in that field you have a 1 or 2 bit colorID.
JNK
I had not thought regarding saving space in the main table, good point! I will keep in consideration thanks once again!
GIbboK
from a view of "Best Practice", would make sense make the main table CARS more readable using values in Look up like Red, instead that using in COLORS ID 1 DESCRIPTION Red and have in the main table CARS the value CAR ID 1 COLOR 1?? thanks
GIbboK
+2  A: 

Clustered indexes can increase the speed of retrieval or inserts, but only when the data is retrieved or updated/inserted in the order that matches the index order.

Otherwise it can decrease performance.

For more detailed answer the question needs to be more specific.

Unreason