Reputation: 33
I'm creating a database for an assignment. When trying to alter a certain table to add a primary key and foreign key a certain error wont let me update the table.
I tried adding a comma at the end of the row which did not resolved the error. Tried to look it up on the internet but I didn't find any relevant information about what can be done to fix it except that it might be a bug.
CREATE TABLE aircraft_model(
Aircraft_model_ID INT,
Model INT,
Manufacture VARCHAR(40),
Range_nmi INT,
Range_km INT,
Length INT,
Width INT,
Height INT
);
ALTER TABLE aircraft_model
ADD CONSTRAINT Aircraft_model_ID_pk PRIMARY KEY (Aircraft_model_ID)
ADD CONSTRAINT Manufacture_fk FOREIGN KEY (Manufacture) REFERENCES Aircraft_Manufacture(Manufacture_ID);
This is what I'm getting after I run the code:
Static analysis:
1 errors were found during analysis.
Missing comma before start of a new alter operation. (near "PRIMARY KEY" at position 64) SQL query:
ALTER TABLE aircraft_model ADD CONSTRAINT Aircraft_model_ID_pk PRIMARY KEY (Aircraft_model_ID) ADD CONSTRAINT Manufacture_fk FOREIGN KEY (Manufacture) REFERENCES Aircraft_Manufacture(Manufacture_ID)
MySQL said: Documentation
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ADD CONSTRAINT Manufacture_fk FOREIGN KEY (Manufacture) REFERENCES Aircraft_Man' at line 3
Upvotes: 0
Views: 1391
Reputation: 1269803
The following code works fine when I try it:
ALTER TABLE aircraft_model
ADD CONSTRAINT Aircraft_model_ID_pk PRIMARY KEY (Aircraft_model_ID),
ADD CONSTRAINT Manufacture_fk FOREIGN KEY (Manufacture) REFERENCES Aircraft_Manufacture(Manufacture_ID);
Here is a db<>fiddle.
Upvotes: 1