Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2011
    Posts
    2

    I am very confused.....

    hi guys.. i am designing a brand new car database system.. I create entity-relationship model but it seems garbage.i uploaded the model.
    Click image for larger version. 

Name:	Car.jpg 
Views:	28 
Size:	38.0 KB 
ID:	11951
    When i want select something in database i write lots of absurd codes like
    'SELECT
    brand_name,model_name,fuel_type,car_type,engine_lt ,price FROM
    brand,model,fuel,cartype,engine WHERE
    car.brand_id=model.brand_id and
    car.model_id=model.model_id and
    car.fuel_id=fuel.fuel.id and
    car.cartype_id=cartype.cartype_id and
    car.engine_id=engine.engine_id; '

    Is this right way or are there any easy ways to do that database..?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    looks over-engineered to me

    for example, take fuel_type -- why would you split that off into a separate table? why wouldn't you just have fuel_type as an attribute of the car?

    well (he said, answering his own question), the only possibility i can think of is that you want a controlled vocabulary -- you want people entering data for a car to be restrictred to only the values of fuel type that have already been predefined in the fuel table, using a foreign key relationship

    if that's true, then my next question question is, why would you use an id for that, instead of the actual fuel_type value?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2011
    Posts
    2
    yeah you absolutely right r937 and car type table is silly too.. So you say that drop car_type and fuel tables.. Take that values in car table.. And its okey right?

    But i want to ask something another thing you called controlled vocabulary..Can you tell more about that topic because i am curious..
    Last edited by sinan; 07-24-11 at 19:11.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    google it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    He means that you are trying to ensure the values are always spelled the same, which can be almost gauranteed through the use of a foreign key that E-89 is what gets into the car table rather than sometimes you have E-89, E89, Ethanol89 and so on. The reason I say almost gauranteed using foreign keys as you have defined already, the other spellings could be added to your fuel table and then make it into your car table. Most places I have been have had a single code table of some sort and you use those codes as a drop down for selection, to try to ensure you get the correct value, rather than having a 100 or more tables that contain a couple of values and their codes, such as fuel type car type etc...
    Dave Nance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •