MySQL Forums
Forum List  »  Newbie

Foreign Keys usage???
Posted by: it99ama
Date: August 18, 2004 05:18AM

I'm trying to make a foreign key relation between two tables but it doesn't seem to work!
#-------------------------------------
CREATE TABLE operation (
operationID int(11) NOT NULL AUTO_INCREMENT,
name varchar(50) default NULL,
PRIMARY KEY (OperationID)
);

#---
CREATE TABLE agent (
agentID int(11) NOT NULL AUTO_INCREMENT,
name varchar(50) default NULL,
operationID int(11) default NULL,
PRIMARY KEY (agentID),
FOREIGN KEY (operationID) REFERENCES operation (operationID)
);
#----------------------------------------------------

Then when i do an insert like:
INSERT INTO operation VALUES(1,'Newbiemission');
INSERT INTO agent VALUES(' ','Newbie',2);

This should cause an error!?? But it doesn't!
The number '2' inserted into the 'agent' table should cause an error because of the FK!!

What am I doing wrong?

/Andy





Options: ReplyQuote


Subject
Written By
Posted
Foreign Keys usage???
August 18, 2004 05:18AM
August 18, 2004 06:00AM
August 18, 2004 08:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.