If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Schema for Company database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-06-08, 14:32
mikr mikr is offline
Registered User
 
Join Date: Jul 2008
Posts: 2
Schema for Company database

Hi all,
I am new here and also newbie to databases.

I am trying to create a database that will hold information about who owns a company. Something like this:

A company can be own by one or more persons or other companies. Ex.
Google is owned by:
Person1
Person2
Company1
Company2

Futhermore I would like to keep track of the history, how the ownership change over time.

How can this be done?
Reply With Quote
  #2 (permalink)  
Old 07-06-08, 14:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
2 googles 4 u 2 do: party datamodel and supertype/subtype
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-06-08, 14:55
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
One possibility:

CREATE TABLE CompanyOwners_People
(CompanyId INT NOT NULL REFERENCES Companies (CompanyId),
Owner_PersonId INT NOT NULL REFERENCES People (PersonId));

CREATE TABLE CompanyOwners_Companies
(CompanyId INT NOT NULL REFERENCES Companies (CompanyId),
Owner_CompanyId INT NOT NULL REFERENCES Companies (CompanyId));
Reply With Quote
  #4 (permalink)  
Old 07-06-08, 14:56
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Oops. Just in case it wasn't obvious:

CREATE TABLE CompanyOwners_People
(CompanyId INT NOT NULL REFERENCES Companies (CompanyId),
Owner_PersonId INT NOT NULL REFERENCES People (PersonId),
PRIMARY KEY (CompanyId, Owner_PersonId));

CREATE TABLE CompanyOwners_Companies
(CompanyId INT NOT NULL REFERENCES Companies (CompanyId),
Owner_CompanyId INT NOT NULL REFERENCES Companies (CompanyId)
PRIMARY KEY (CompanyId, Owner_CompanyId));
Reply With Quote
  #5 (permalink)  
Old 07-06-08, 17:54
mikr mikr is offline
Registered User
 
Join Date: Jul 2008
Posts: 2
This seems to work fine. Thank you. I did a quick try on OpenOffice - Base but it seems that the program does not like the double relation between "CompanyOwners_Companies" and "Companies". It allows me to define it but when I save it and reopen it's gone. Is this the normal behavior for this program or am I doing something wrong.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On