We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,171 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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?

2
Contributors
1
Reply
33 Minutes
Discussion Span
5 Months Ago
Last Updated
3
Views
Question
Answered
riahc3
 
Team Colleague
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
Moderator
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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0576 seconds using 2.67MB