It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Understanding of SQL Relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Understanding of SQL Relationships" Watch "Understanding of SQL Relationships" New topic

Understanding of SQL Relationships

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

My apologizes if this is not the right post .

One-to-one relationships are single-valued in both directions.

My understanding with the above is that

Consider a Zip Table

ZipNo Studentname

12 Harry
13 Kiran

And a Student Table

ID Name ZipNo

101 Harry 12

and there should not be any more student with zipno 12 . Then this will be a One to One

Am i right ?

Save India From Corruption - Anna Hazare.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
No, that is not a one-to-many relationship because it is not a relationship.
It is only a relationship when the data join different tables.

Student table-----Tuition fees table

That will be a one-to-one relationship

Student table

Campbell 1234
Ravi 1235

Tuition Fees table
1234 $1.23
1235 $938475937459676734096740364376093470687234096732472340.99

You can have a one-to-many relationship

Student table as before
Residences table
King's Hall 99
Queen's Hall 98

Accommodation table
1234 99
1235 99

You can work out from that, both students shown live at King's Hall at present, and one has rather more tuition fees to pay than the other.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks Campbell , Your explanation is very nice .

I understood how the tables should be written for supporting relationships.
I agree. Here's the link:
subject: Understanding of SQL Relationships
It's not a secret anymore!