Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

relationship in Mysql

Posted on 2002-03-14
3
835 Views
Last Modified: 2010-08-05
Hai all,

Presently Iam using phpMyAdmin software to create databases in mysql.
I don't know how to create relationships between the tables.

can anyone who r familiar with the above software can help me out.

Thanks,
Manju
0
Comment
Question by:manju70
  • 2
3 Comments
 
LVL 6

Expert Comment

by:andreif
ID: 6867547
Hm, what do you mean exactly by "creating relationship"?

There is only tables in MySQL and all relationships you must keep in your mind - so, it's your own business how to join tables and which criteria to use.

If you mean creating n-m relationship between two tables, you have to create extra table, for example

You have tables BOOK and CATEGORY
where BOOK has book_id as key and CATEGORY has category_id as a key. To make a relationship, you have to create table
BOOK_CATEGORY (table name is up to you :))
with columns book_id and category_id.
Now, to connect books with categories you will add records to BOOK_CATEGORY table
0
 
LVL 5

Accepted Solution

by:
kelfink earned 30 total points
ID: 6869208
By relationships, you probably mean FOREIGN KEY, and yes, sort of, mysql can support them.

The syntax is such as:

create table a ( id int not null primary key );
create table b ( a_id int not null,
                 foreign key (a_id) references a );

But, mysql doesn't enforce the integrity, unless you use InnoDB tables...

 insert into a ( id ) values ( 1 );

0
 
LVL 5

Expert Comment

by:kelfink
ID: 6869216
I hit submit too soon.

Basically, without using innodb, you will be able to do this:
insert into a ( id ) values ( 1 );
insert into b ( a_id ) values ( 2 );

which should fail, if it were being enforced.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Amazon Redshift 2 39
Determining creation & modification dates on MySQL tables 4 45
Complex SQL statement in VB.NET 7 31
Combining Queries 7 28
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question