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:

Create table MANUFACTURER(
Manuf_name char(16) Not Null,
Manufacture_id Varchar(2) Not Null,
Primary Key (Manufacture_id));

Create table MODELS(
Model_name varchar(16) Not Null,
Model_id Varchar(2) Not Null,
Manufacture_id Varchar(2) Not Null,
Primary Key (Model_id),
FOREIGN Key (Manufacture_id) REFERENCES MANUFACTURER);

Create table OPTIONS(
option_name varchar(16) Not Null,
option_id Varchar(2) Not Null,
Primary Key (option_id));

Create table CAR(
year varchar(4) Not Null,
car_id Varchar(3) Not Null,
color char (20) Not Null,
Manufacture_id Varchar(2) Not Null,
Model_id Varchar(2) Not Null,
stock_num varchar (3) Not Null,
price float Not Null,
mileage varchar (10) Not Null,
Vin_num varchar (7) Not Null,
Primary Key (Vin_num),
Foreign Key (car_id) references CAR_OPTIONS,
Foreign Key (Manufacture_id) references MANUFACTURER,
Foreign Key (model_id) references MODELS);

Create table CAR_OPTIONS (
car_id Varchar(3) Not Null,
option_id Varchar(3) Not Null,
Primary Key (car_id),
Foreign Key (option_id) references OPTIONS);

error occurs if i try to insert something like: 

Insert into CAR (year,car_id,color,manufacture_id,model_id,stock_num,price,mileage,vin_num)
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..

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.