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.
| Author |
Topic |
|
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2010-04-09 : 12:06:40
|
| i have two tables one is employee other is joblocationjoblocationjoblocationid primarykeyjoblocationnameemployeeemployeeid primarykeyemploynameemployeejoblocation foreignkey uniqueis 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. |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-09 : 13:52:29
|
quote: employeeid primarykeyemploynameemployeejoblocation foreignkey
Remove the unique constraint and thats enough map an employee with only 1 department. |
 |
|
|
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) |
 |
|
|
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2010-04-09 : 14:19:18
|
| thanks alotis there a way to show this is finshed |
 |
|
|
|
|
|