Can't do a relation between tables
I habe table one with
Col 1 (PK)
Col 2 (NN)
Col 3 (NN)
Col 4 (NN)
Col 5 (NN)
Col 6
Col 7
Col 8
Then I create table two with
Col 1 (PK) (AI)
Col 2
Col 3 (FK)
That col 3 from table two is col 1 from table one. I tried to make the FK relation in Workbench and it does not let me!
I drop that table two....recreate from sratch and it says:
ERROR 1005: Can't create table 'bd.table2' (errno: 121)
SQL Statement:
CREATE TABLE bd.table2 (
col1 INT NOT NULL AUTO_INCREMENT ,
col2 VARCHAR(70) NULL ,
col3 INT(11) NOT NULL ,
PRIMARY KEY (col1, col3) ,
INDEX col3_idx (col3 ASC) ,
CONSTRAINT col3
FOREIGN KEY (`col3` )
REFERENCES `bd`.`table1` (`col3` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
What is wrong?
33 Minutes
Discussion Span
riahc3
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
A constraint needs a unique name. col3 is already in use.
pritaeas
Posting Prodigy
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,459
Skill Endorsements: 86
Question Answered as of 5 Months Ago by
pritaeas