Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

constraints not registering

Status
Not open for further replies.

jjjamie

Programmer
Sep 11, 2002
10
GB
Hi all,

I am trying to create a database table that will act like a linked list by using self referencing. I have used the following definitions:

CREATE TABLE partslist(
id INT AUTO_INCREMENT,
PRIMARY KEY(id),
partid INT NOT NULL,
INDEX partid_ind (partid),
FOREIGN KEY (partid) REFERENCES parts(id),
nextpart INT NOT NULL -- Points to the next part in the list
) TYPE=INNODB;

INSERT partslist VALUES(1, 1, 1); -- dummy part (pointed to in order to end linked list)

ALTER TABLE partslist ADD INDEX nextpart_ind (nextpart);
ALTER TABLE partslist ADD FOREIGN KEY (nextpart) REFERENCES partslist(id);

-- Add some parts (starts with last part in list due to constraints)
INSERT partslist VALUES(2, 15, 1); -- nextpart is the dummy part
INSERT partslist VALUES(1, 20, 2); -- links to next part (2)


This works but the problem is with the constraints. For some reason I can do this:

INSERT partslist VALUES(3, 14, 99);

99 does not exist in the table. I should get an error!!


Does anyone have any idea why the constraints aren't registering?

Thanks in advance,

Jamie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top