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
 General SQL Server Forums
 New to SQL Server Programming
 How to design this one

Author  Topic 

skiabox
Posting Yak Master

169 Posts

Posted - 2008-10-30 : 07:11:16
I have a table with buildings
(buildingID as primary key,
streetName column
streetNumber column) etc.
I want to create a new table with some jobs that must be made uppon the building.
I have created a new table with all the jobs as columns and with buildingID as a foreign key.
What will be the primary key of this new table?
I also believe that the relationship between the two tables must be one-to-one.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-10-30 : 07:15:33
No, the relationship would be one-to-many as you can have many jobs on one building surely?

You can create a jobid as your primary key.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-30 : 07:16:07
Doesn't sound like it should be 1 to 1

Surely there can be many jobs for the same building?

Regards,

-------------
Charlie
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-30 : 07:16:34
I'm too slow.

-------------
Charlie
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-10-30 : 07:20:07
Nevermind..
Go to Top of Page

skiabox
Posting Yak Master

169 Posts

Posted - 2008-10-30 : 07:20:16
The buildings are unique of course but the jobs can vary depending on the current building.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-10-30 : 07:28:21
Yes, but that still makes it a one to many and not a one to one.
Go to Top of Page

skiabox
Posting Yak Master

169 Posts

Posted - 2008-10-30 : 08:15:45
So you suggest a table with two columns for example?
(jobID as the primary key column and jobName with the name of the job)
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-10-30 : 08:27:58
No, I suggest it with three columns at least, jobid, buildingid, jobname etc..
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2008-10-30 : 21:31:06
skiabox, in reality, few tables are 1 to 1 relationship - because if it is 1 to 1 relationship, you are better off inserting it as a column in the same table than a separate table. It is usually 1 to many.

Regards,

Eugene

check out my blog at http://www.aquariumlore.blogspot.com
Go to Top of Page
   

- Advertisement -