MySQL Forums
Forum List  »  InnoDB

Referential Integrity not working
Posted by: Vikram Malhotra
Date: October 30, 2008 08:36PM

Hello all,

I was just trying to implement a simple foreign key contraint, but it doesn't work.

-- -----------------------------------------------------
-- Table `tbl_customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS tbl_customer (
cust_id MEDIUMINT NOT NULL AUTO_INCREMENT ,
cust_lastname VARCHAR(45) NULL ,
PRIMARY KEY (cust_id) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `tbl_order`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS tbl_order (
ordr_id MEDIUMINT NOT NULL AUTO_INCREMENT ,
ordr_name VARCHAR2(100) NOT NULL ,
cust_id MEDIUMINT NOT NULL ,
PRIMARY KEY (ordr_id) ,
INDEX (cust_id) ,
FOREIGN KEY (cust_id )
REFERENCES mydb.tbl_customer ( cust_id ) )
ENGINE = InnoDB;

Whenever I insert a record in table for orders(FK), without entering a record in customer's table(PK), it does not hold the foreign key constraint. What could be going wrong?

Thanks for any help
Vikram



Edited 2 time(s). Last edit at 10/30/2008 08:40PM by Vikram Malhotra.

Options: ReplyQuote


Subject
Views
Written By
Posted
Referential Integrity not working
5507
October 30, 2008 08:36PM
3414
February 10, 2009 02:16AM


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.