1,105,254 Community Members

Can't do a relation between tables

Member Avatar
riahc3
 
1,397 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
0
 

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?

Member Avatar
pritaeas
mod_pritaeas
11,291 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
1
 

A constraint needs a unique name. col3 is already in use.

Question Answered as of 1 Year Ago by pritaeas
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article