Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 composite PK issues.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sapator
Constraint Violating Yak Guru

Greece
462 Posts

Posted - 02/08/2014 :  14:56:13  Show Profile  Reply with Quote
Hello.
I must create a DB and my problem is this:
Table Geolocation
Table Cost_Center
Table GeoToCost
Table InkToCost
Table Ink_Type

Cost_Center can reference 2 or more Geolocations So i made the intermediate table GeoToCost
Ink must reference a Cost_Center so i made the intermediate table InkToCost
The problem i am facing is how will determine in what Geolocation an Ink can be because the Cost_Center can be in more than one Geolocation.
I am thinking of making a composite PK on table InkToCost with PK Cost_Center id and GeoToCost id.So i will know that an ink of type A has a Cost_Center name X that resides on Geolocation GeoA.
I have 2 problems here.
1st if this the way to go and second, how will i reference this query.
Do i need to add also GeoToCost id on ink_Type table?

I haven't made the tables yet so i don't have a schema but if required i will make test tables.

Anyhow FK's are Geolocation --> FK GeoToCost <-- Cost_Center ,
Cost_Center --> InkToCost <-- Ink_Type ,
So do i need also Cost_Center --> InkToCost(PK Cost_Center_id, GeoToCost_id) <-- Ink_Type ?
Of can i just put on InkToCost the Cost_Center_id,Geolocation_id and don't make a composite PK?
Thanks.

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/11/2014 :  02:45:04  Show Profile  Reply with Quote
As I understand its enough if you just include GeoToCost in InkToCost as each record in GeoToCost represents a relationship of cost center to ONE particular location. Then you'll be able to link ink to cost center and also to its location.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sapator
Constraint Violating Yak Guru

Greece
462 Posts

Posted - 02/11/2014 :  21:03:45  Show Profile  Reply with Quote
Thanks. I will try and if i have any problems i will let you know.

Edited by - sapator on 02/11/2014 21:04:27
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/12/2014 :  00:27:46  Show Profile  Reply with Quote
ok..let me know how you got on

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next 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.05 seconds. Powered By: Snitz Forums 2000