views:

36

answers:

1

I am working for a project to create a database for saving different persons contact details in SQL. For example, X person saves 10 contacts, Y persons save 15 contacts, z persons save 20 contacts and so on. I cant create separate tables to save contacts of x,y,z and so on. But i just want to know the alternative method to do that. Is there any easy method to save different cotacts and is there any easy method to retrieve it. I'm just a student, i don't know much about sql and don't have much experience in this. So i need your help to know much about this.

A: 

You need one table of contacts, with a column of user ID.

Another Table of Users (Persons) and a FK between them.

This is better.

Dani
thanks for your response...i created a table "members" with id and mobile no as PK,ID Name Mobno________________1 john 99999999992 sam 8888888888then i saved their contacts in the table "contacts" with id and mobieno as PK.ID Name Mobileno______________________1 gem 898989891 tim 909090901 sam 88888888882 tim 909090902 david 55445544Here john save a contact called david, now i want to send a request to sam saying that "do u know david with 55445544 mobileno."How to do that dude?
jagan
The id is enough for FKSELECT * from tblContacts T, Person P where T.PersonID = P.PersonID and P.Name = 'David' (you don't need and P.Phone = '12323232') There is a better way to "Write" it using a JOIN (you are joining the tables on ID column).
Dani
ACtually - that will give you all david's contacts, you need to do it for sam's id and see if david is one of his contacts.
Dani