Showing posts with label theory. Show all posts
Showing posts with label theory. Show all posts

Friday, March 30, 2012

relationships problem

VB.NET 05 (ADO.NET) / SQL SERVER 05.
i have a many-to-many relationship. therefore, according to the normalisation theory, i introduced a new table which acts as a link between them.

1) tblOrders
PK: orderID

2) tblOrdersItems
FK: orderID
FK: itemID

3) tblItems
PK: itemID

the user wishes to view the details of a particular order which should include all the items
contained withing that particular order.

question: what is the technique to be used in order to get this done?

i) dim varOrderID as integer
ii) select tblOrdersItems.itemID where orderID = varOrderID
iii) HOW TO NOW FETCH the details of the items contained in this order from tblItems which should be displayed on a datagrid?

I believe you could use query similar to

SELECT list of field here From TblItems I INNER JOIN tblOrdersItems OI ON I.itemID=OI.itemID

WHERE OI.orderID=MyIDHere

|||

You can use the following query,

Code Snippet

Select * from tblOrders A

Join tblOrdersItems B on A.orderId = b.orderId

Join tblItems C on C.itemId = B.ItemId

Where

A.orderId = @.YourOrderId

sql

Wednesday, March 28, 2012

Relationship between t-Sql and "Set Theory"

I have always heard that much of t-sql is based on "set theory". I had Set theory in high school and I remember it as being simple Unions, Intersections, Differences of Sets. By a Set I mean a collection such as {2,5,7,8,9, ...) That could well described a single row in a table. By unioning several of these rows we could end up with a table.

But how does that relate to t-sql such as

select * from <table name> Where <condition 1> ?

Is it simply that the result returned by the query is a Set? (if so, a Set is simply being used as a synonym for a Collection. No set theory involved.)

TIA,

barkingdog

This is quite a large subject =;o)

Perhaps the best way is to point you to some reading, to get you started.
http://en.wikipedia.org/wiki/Relational_model

/Kenneth