This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Understanding of SQL Relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Understanding of SQL Relationships" Watch "Understanding of SQL Relationships" New topic
Author

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
Sheriff

Joined: Oct 13, 2005
Posts: 37890
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Understanding of SQL Relationships
 
Similar Threads
Should we use DefaultTableColumnModel with TableModel ?
Newbie Question: Referential Integrity and Cascading
EJB QL question from exam latest
CMR and EJBQL
adding to a table with no primary keys