Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

relationship in Mysql

Posted on 2002-03-14
3
Medium Priority
?
861 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…
Suggested Courses

604 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