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!

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.

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 :)

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.

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

<(_ _)>

which version of sql mngr you are using 2000 or 2005


and u can do same task by using trigares

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.