hi,
can i anybody tell me..the use of FOREIGN KEY.I am creating two tables,one with the PRIMARY KEY and the other one is the FOREIGN KEY.
For Example :
- create table customer(cid int not null,cname varchar(50),PRIMARY KEY(cid))type=innodb;
- create table orders(orderid int not null PRIMARY KEY,cost int not null,cid int not null,index(cid),FOREIGN KEY(cid) REFERENCES PRIMARY KEY(cid))type=innodb;
what will do the FOREIGN KEY ?when i am trying to insert a record in the FOREIGN KEY table(ORDERS TABLE),its INSERTING .But its not reflected in the CUSTOMER TABLE.
Same thing,when i am trying to insert a record in the CUSTOMER TABLE,its INSERTING.But its not reflected in the ORDERS TABLE.
Same like for DELETING and for UPDATING.......please help me out.The need of FOREIGN KEY.I cant get it properly.thanks