Help database design

Reply

Join Date: Nov 2008
Posts: 3
Reputation: starter is an unknown quantity at this point 
Solved Threads: 0
starter starter is offline Offline
Newbie Poster

Help database design

 
0
  #1
Nov 28th, 2008
Hi
I am trying to insert data into 1 of my table and I get this error:
Microsoft Access can't append all the records in the append query.
Microsoft Access set 0 fields to Null due to type conversion failure, and it didn't add 1 records to the table due to key violation, 0 records due to lock violation, and 0 records due to validation rule violation.

My design is:

  1. CREATE TABLE MANUFACTURER(
  2. Manuf_name CHAR(16) NOT NULL,
  3. Manufacture_id VARCHAR(2) NOT NULL,
  4. PRIMARY KEY (Manufacture_id));
  5.  
  6. CREATE TABLE MODELS(
  7. Model_name VARCHAR(16) NOT NULL,
  8. Model_id VARCHAR(2) NOT NULL,
  9. Manufacture_id VARCHAR(2) NOT NULL,
  10. PRIMARY KEY (Model_id),
  11. FOREIGN Key (Manufacture_id) REFERENCES MANUFACTURER);
  12.  
  13. CREATE TABLE OPTIONS(
  14. option_name VARCHAR(16) NOT NULL,
  15. option_id VARCHAR(2) NOT NULL,
  16. PRIMARY KEY (option_id));
  17.  
  18. CREATE TABLE CAR(
  19. YEAR VARCHAR(4) NOT NULL,
  20. car_id VARCHAR(3) NOT NULL,
  21. color CHAR (20) NOT NULL,
  22. Manufacture_id VARCHAR(2) NOT NULL,
  23. Model_id VARCHAR(2) NOT NULL,
  24. stock_num VARCHAR (3) NOT NULL,
  25. price FLOAT NOT NULL,
  26. mileage VARCHAR (10) NOT NULL,
  27. Vin_num VARCHAR (7) NOT NULL,
  28. PRIMARY KEY (Vin_num),
  29. FOREIGN Key (car_id) REFERENCES CAR_OPTIONS,
  30. FOREIGN Key (Manufacture_id) REFERENCES MANUFACTURER,
  31. FOREIGN Key (model_id) REFERENCES MODELS);
  32.  
  33. CREATE TABLE CAR_OPTIONS (
  34. car_id VARCHAR(3) NOT NULL,
  35. option_id VARCHAR(3) NOT NULL,
  36. PRIMARY KEY (car_id),
  37. FOREIGN Key (option_id) REFERENCES OPTIONS);
  38.  
  39. error occurs if i try to INSERT something LIKE:
  40.  
  41. INSERT INTO CAR (YEAR,car_id,color,manufacture_id,model_id,stock_num,price,mileage,vin_num)
  42. VALUES ("2008","1","Blue","1","2","12","13000","20000","12398");

This occurs when I try to add data into the car or CAR_OPTIONS table
Please help..
Last edited by peter_budo; Nov 29th, 2008 at 6:10 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 60
Reputation: pclfw is an unknown quantity at this point 
Solved Threads: 5
pclfw pclfw is offline Offline
Junior Poster in Training

Re: Help database design

 
0
  #2
Jan 9th, 2009
Originally I thought that this was in the wrong forum. But I was wrong.

Your query regarding the foreign key violations should be fairly trivial if you trace back through all of the tables ensuring that the correct data is in place BEFORE you try to insert the CAR row. Also you might want to have a look at the CAR_OPTIONS table. It has a PK on the CAR_ID value. PK's are (usually) unique, while the name CAR_OPTIONS implies multiple rows for each car. This would give rise to the Key violation error you report.

However now the Database Design problem.

Looking at your SQL code I see that you have FK releationships from the CAR table to the MANUFACTURERS table and the MODELS table. Surely a MODEL is owned by the MANUFACTURER and you then only need to FK to the MODELS table. Yes; different car models MIGHT have the same name, bu they WILL have different MANUFACTURERS and thus a different MODELS.MODEL_ID.

I do not understand the OPTIONS and CAR_OPTIONS system(s). An option for a car (real world) may have a name shared by many other options. i.e. 'Metalic Paint' or 'Air Conditioning'. While the NAMES of these options may be the same from manufacturer to manufacturer, the actual OPTIONS themselves are not. Thus I would have expected the OPTIONS table to include the MODEL_ID and be FK'ed on this. Then I would expect the CAR_OPTIONS to just hold the CAR_ID and the OPTION_ID. FK's can be placed on both of these columns but are not usually necessary.

Hope that you can understand my meanderings and that they help.
Last edited by pclfw; Jan 9th, 2009 at 10:32 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC