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 2005 Forums
 Transact-SQL (2005)
 tables

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-08 : 05:37:10
Hi

Which one is better from bellow?Having one table like this:


ID/NAME/JoBID/COUNTRYID/LANGUAGEID
----------------------------------
1/Tom/teacher/USA/English
2/John/driver/Saudi/Arabic

Or more tables with relations like this:

ID/NAME/JoBID/COUNTRYID/LANGUAGEID
----------------------------------
1/Tom/1/2/2
2/John/4/5/3

LANGUAGENAME/LANGUAGEID
-----------------------
Franch/1
English/2
Arabic/3

COUNTRY/COUNTRYID
-----------------
France/1
USA/2
UK/3
Italy/4
Saudi/5
India/6

JOB/JOBID
----------
teacher/1
tailor/2
butcher/3
driver/4

When should we use id instead of name?
And
another question:
when i want to desplay my table how should i do it? i want the fields be shown by their names not ID.

Thanks for your help

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-08 : 05:45:10
Relations!
select
p.Name,
l.Languagename,
c.Country,
j.Job
from persons p
join languages l on l.languageid = p.languageid
join countries c on c.countryid = p.countryid
join jobs j on j.jobid = p.jobid


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-09 : 03:09:21
Thank you very much.
but i dont know when one table should be used and when more tables with relations between them (as in example) ?
please enlighten it for me
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-09 : 04:55:13
use separate table when you have more than one attribute.

Example for the Country, you can have other attribute like Capital, National Language, Area, Population etc.

Read more about Normalization.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -