Solved

relationship in Mysql

Posted on 2002-03-14
3
823 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now