Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 relationship

Author  Topic 

sravanim
Yak Posting Veteran

58 Posts

Posted - 2013-10-28 : 08:35:24
what is zero to many relation ship,Please explain with example?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-28 : 08:38:13
It is used to describe the case where one side of the relationship may have zero or more entities that match the other side of the relationship.

Think of a the classic example of customers and orders. Each customer may have placed zero or more orders. So if you were to store customer information in one table, and order information including a customer id in an order table, then there can be zero or more rows in the order table for any given customer id.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-28 : 09:02:22
And in DB you represent it by means of an intermediate table
like
Customer,Orders and CustomerOrders
Customer will have details of customer like Number, name, contact details etc
Order will have details like Number, description, Quantity, Price, Date etc

Based on who many orders a customer placed there will be 0 to multiple records in CustomerOrders which will just have fields CustomerID and OrderID to indicate relationship. The corresponding attributes are fetched from the master tables using foreign key relationships set

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-10-31 : 13:13:26
quote:
Originally posted by visakh16

And in DB you represent it by means of an intermediate table
like
Customer,Orders and CustomerOrders
Customer will have details of customer like Number, name, contact details etc
Order will have details like Number, description, Quantity, Price, Date etc

Based on who many orders a customer placed there will be 0 to multiple records in CustomerOrders which will just have fields CustomerID and OrderID to indicate relationship. The corresponding attributes are fetched from the master tables using foreign key relationships set

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


That may help the OP, but what you are describing is a Many-to-Many.
Go to Top of Page
   

- Advertisement -