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?

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

commented: Solution +4
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.