0

hi,im really new to MySQL,can some one help me in joining table pls...i hv 2 tables,customer table and record table

customer table with CustomerID,Customer Name,CustomerAddress,
record table with RecordID,CustomerID,Date,

how to make the CustomerID in record as foreign key? how to join that two tables so that record will be deleted when i delete the customer id? :sad:

i hope u guys could give me a hand :cry: thanks!

7
Contributors
7
Replies
15
Views
11 Years
Discussion Span
Last Post by hirenpatel53
0

Just to take note that there is no Foreign key in MySQL unless your database's type is InnoDB. I assume you are using MyISAM.

DELETE FROM Customer WHERE CustomerID = yourcustomerid;
DELETE FROM Records WHERE CusomerID = yourcustomerid;

Hope it helps.

0

Just to take note that there is no Foreign key in MySQL unless your database's type is InnoDB. I assume you are using MyISAM.

Hope it helps.

Hi Friends,

I also have read in many websites that we cannot create foreign key in MyISM type database or tables. But It is possible to create foreign key in MyISM type database or tables. Here I am submitting two tables and the relationship between them using foreign key concept. So do practice in your maching also.
Two tables
1. Country
2. State

SQL for Country:
Create Table Country(Id int(2) Primary Key Not Null Auto_Increment,
CName varchar(10))

SQL for State:
Create Table State (Id int(2) Primary Key Not Null Auto_Increment,SName varchar(10),cid int(2),foreign key (cid) references country(id))

Try, it is working successfully in my machine (laptop).
Cheers :)

0

Just use it as if it was a foreign key!

A true foreign key would enable you to enforce relational integrity, but you can work with a database without it actually being enforced. You just carry out joins in the usual way and they work.

What you lose out on is not automatically getting a warning when there is an error such as no parent record for your foreign key eg foreignID should be 1023 and you entry 1032, for which no record exists in the other table. This would be accepted in MyISM but rejected in InnoDB.

0

what if im using mysql?
n i wanna make a foreign key using PhpMyAdmin @local host.
some one help me please...

<(_ _)>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.