Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
SQL
CREATE TABLE vendor (
V_code INTEGER NOT NULL UNIQUE,
V_name VARCHAR(35) NOT NULL,
V_contact VARCHAR(25) NOT NULL,
V_Year_founded DATE NOT NULL,
V_phone CHAR(12) NOT NULL,
V_state CHAR(2) NOT NULL,
PRIMARY KEY (V_code)) engine=InnoDB;

SQL
CREATE TABLE product (
P_code INTEGER NOT NULL UNIQUE,
P_descript VARCHAR(35) NOT NULL,
P_quan SMALLINT NOT NULL,
P_price DECIMAL(8,2) NOT NULL,
P_discount DECIMAL(5,2) NOT NULL,
V_code INTEGER,
PRIMARY KEY (P_code),
FOREIGN KEY (V_code) REFERENCES vendor(V_code)
)engine=InnoDB;


Insert values into the tables
SQL
INSERT INTO vendor
VALUES (21225,'Bryson, Inc.','Smithson','1990-10-08','723-223-3234','TN'),
(21226,'D&E Supply','Corener','1985-08-08','974-113-3255','VA'),
(21227,'Rubicon Systems','Hakford','1979-03-08','322-113-3255','CA');

SQL
INSERT INTO product
VALUES
(01,'Titanium drill bit',75, 141.50, 0.06,21226),
(02,'Gold drill bit', 66, 19.50, 0.08,21227),
(03,'Silver drill bit', 62, 8.50, 0.5,21225),
(04,'Aluminum drill', 61, 6.50, 0.9,21225),
(05,'Silver drill bit', 62, 12.50, 0.5,21227),
(06,'Gold drill bit', 66, 16.50, 0.28,21225);


What I have tried:

I have gone over the code but cant find my mistake
Posted
Updated 16-Nov-22 21:54pm
v2
Comments
Wendelius 16-Nov-22 23:20pm    
What is the error you're referring to?
Member 15627495 17-Nov-22 0:04am    
ig your primary key are 'auto increment' , just pass with '' a blank value.
you made your primary key 'UNIQUE' but not 'auto-increment'
keep empty values for v_code and p_code :
insert into 'table' values ( '','value',value_integer,'value_varchar',.....)
Dave Kreskowiak 17-Nov-22 8:40am    
Next time you ask a question, remember, the error message is ALWAYS important to solving the problem.

1 solution

Don't use "UNIQUE", use "AUTO_INCREMENT", and let the database control the values. See MySQL :: MySQL 8.0 Reference Manual :: 13.1.20 CREATE TABLE Statement[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900