?
Solved

relationship in Mysql

Posted on 2002-03-14
3
Medium Priority
?
849 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
[X]
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
  • 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 90 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 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