SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Tuple relational calculus
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pluto3
Starting Member

3 Posts

Posted - 06/06/2012 :  10:25:06  Show Profile  Reply with Quote
Hi!

I'm trying to translate this tuple relational calculus to SQL.
At top of the picture the database structure is given and then there is the tuple relational calculus.


My translation to SQL is:


Is this correct? And if not, what have I missed?
Thanks for answearing.

Edited by - Pluto3 on 06/07/2012 07:50:52

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/06/2012 :  10:32:43  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Don't think this is a natural join and you have missed the join conditions. Also you have missed out the table Vara with the associated join.

Try translating it into english first

t.adv such that t in Lager and exists (u,v,w) such that u in Avdelning and v in Lager and w in Vara and t.foretag = v.foretag and ...

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nigelrivett on 06/06/2012 10:35:48
Go to Top of Page

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 06/06/2012 :  10:46:19  Show Profile  Visit robvolk's Homepage  Reply with Quote
quote:
Originally posted by nigelrivett

Don't think this is a natural join and you have missed the join conditions. Also you have missed out the table Vara with the associated join.
Natural joins always occur on common column names.
Go to Top of Page

Pluto3
Starting Member

3 Posts

Posted - 06/06/2012 :  10:47:58  Show Profile  Reply with Quote
nigelrivett, im think like this: Avdelning, Lager and Vara are associated, and they are associated by the following conditions: u.avd = v.avd and v.varunr = w.varunr. Hence we should be able to use NATRUAL JOIN in SQL as it does those associations for us?
Then we have the conditions w.typ = 'blomma' and u.vĂ¥ning = 1 (translated in english (this is a database for a department store) w.type = 'flower' and u.floor = 1) and we then group by the avd (department that meet the conditions of selling flowers and beeing on floor 1.)

robvolk, do you know if my translation is correct?

Edited by - Pluto3 on 06/06/2012 10:54:40
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/06/2012 :  10:59:03  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
OK - didn't notice that - also missed the third table in your script
Looks ok - I would have distinct rather than group by - and do you need to exclude nulls. Depends on the adv column definition.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nigelrivett on 06/06/2012 11:02:28
Go to Top of Page

Pluto3
Starting Member

3 Posts

Posted - 06/06/2012 :  11:05:42  Show Profile  Reply with Quote
nigelrivett, that seems like a better solution. So the SQL would then be:

And that would give me all the departments (not displaying the same several times) on floor 1 selling flowers right?
Just want to make sure that i got it.

Edited by - Pluto3 on 06/07/2012 07:51:05
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/06/2012 :  11:19:09  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Looks like it. You are joining on avd so it can't be null.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/07/2012 :  08:11:11  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Not very friendly to remove the question - other peple might be interested.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 06/07/2012 :  09:25:34  Show Profile  Visit robvolk's Homepage  Reply with Quote
quote:
Originally posted by nigelrivett

Not very friendly to remove the question - other peple might be interested.
I think their professors are amongst the interested parties.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000