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
 table schema

Author  Topic 

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-09 : 12:06:40
i have two tables one is employee other is joblocation

joblocation

joblocationid primarykey
joblocationname

employee

employeeid primarykey
employname
employeejoblocation foreignkey unique

is this the best setup to make sure that each employee has a location that exists and can only be in one location?

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-09 : 12:13:13
Works for me. :)

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-09 : 13:45:29
if i try and put a second employee in the department. will it error?

departments can have multiple people so how do i make it so that that a particular employee can be attached only to one department
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-04-09 : 13:51:26
quote:
[employeejoblocation foreignkey unique




I don't think that you need to add unique contraint here as it will not allow you to insert another employee record for same department.

Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-04-09 : 13:52:29
quote:

employeeid primarykey
employname
employeejoblocation foreignkey



Remove the unique constraint and thats enough map an employee with only 1 department.

Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-04-09 : 14:04:21
I am little bit confused over your requirement.

You want to add one employee to one location and a single location can have many employees (Many to one relationship )

Or

You want to add one employee to one or more locations. (Many to many relationship)
Go to Top of Page

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-09 : 14:19:18
thanks alot

is there a way to show this is finshed
Go to Top of Page
   

- Advertisement -