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 |
|
coopervegas
Starting Member
2 Posts |
Posted - 2011-03-26 : 18:11:09
|
| This may be a basic question; I am fairly new to SQL.I have two tables 'Players' and 'Company'. Each has a primary key 'PlayerID' and 'CompanyID' respectively.I want to create a new table called 'Company Ownership' that would keep track of who owns shares of stock of a company.My problem is that I want both players AND companies able to own stock.For example: Player1 owns 100 shares of CompanyAPlayer1 owns 150 shares of CompanyBPlayer2 owns 175 shres of CompanyAPlayer2 owns 200 shares of CompanyBCompanyA owns 500 shares of CompanyBI'm not sure how to structure the 'Company Ownership' table where there is a multi-column primary key, one column for 'company' one for 'playerid_owner' and one for 'companyid_owner'. I guess I could make the player_id_owner zero/null when a companyid owns it and vice versa, but I'm thinking there is a better solution.Thanks for any help. |
|
|
coopervegas
Starting Member
2 Posts |
Posted - 2011-03-26 : 19:03:48
|
| I've been looking but I just don't see any SQL mechanic for my problem; maybe I need to redesign my database. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-03-27 : 01:13:53
|
| what you could do is create two columns company_id or player_id that corresponds to company or player that owns stock. then create a check constraint to check if either one of them is not null. then add a new id as identity and make it pk.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|