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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Reservation System

Author  Topic 

TheOxblood
Starting Member

19 Posts

Posted - 2011-09-18 : 01:55:19
I have two tables (Company and Persons) in my reservation system,

Company Table
-CompanyID
-CompanyName
-Fname
-Lname
-Street
-City
-ContactNo

Persons Table
-PersonID
-Fname
-Lname
-Street
-City
-ContactNo

Their only difference is the COMPANYNAME.
Then each transaction can either be a COMPANY or PERSON..

Reservation Table
-ReservationNo
-ClientID
-...
-...
-...

How can I insert a value for ClientID?

Vonn Liquiran

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-18 : 03:17:09
sorry not fully clear
Is the question to get associated company/person who did reservation? or is it in populating Reservation table from Person/Company table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-18 : 03:58:10
If Persons are part of a Company then add a CompanyID column to the Persons Table

If Persons and Companies are not related/linked then either:

a) have two columns in Reservation table, one for CompanyID and the other for PersonID and ensure that exact one is filled in on each row
b) Have a column that indicates whether the reservation is for an CompanyID or a PersonID and a single column that is the actual ID.

Neither of these approaches is ideal though.
Go to Top of Page

TheOxblood
Starting Member

19 Posts

Posted - 2011-09-18 : 05:30:09

quote:
Originally posted by visakh16

sorry not fully clear
Is the question to get associated company/person who did reservation? or is it in populating Reservation table from Person/Company table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Yes, I want to know who did the reservation. I having a hard time in creating the relationship between the 3 tables I have.





Vonn Liquiran
Go to Top of Page

TheOxblood
Starting Member

19 Posts

Posted - 2011-09-18 : 05:39:57
quote:
Originally posted by Kristen

If Persons are part of a Company then add a CompanyID column to the Persons Table

If Persons and Companies are not related/linked then either:

a) have two columns in Reservation table, one for CompanyID and the other for PersonID and ensure that exact one is filled in on each row
b) Have a column that indicates whether the reservation is for an CompanyID or a PersonID and a single column that is the actual ID.

Neither of these approaches is ideal though.



I got your LETTER B idea! Thank You very much! I need to create One table for the CLIENTTYPE then relate it to the Reservation Table!


THANKssss! :) This system is for my System and Analysis Project

Vonn Liquiran
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-18 : 05:51:46
quote:
Originally posted by TheOxblood


quote:
Originally posted by visakh16

sorry not fully clear
Is the question to get associated company/person who did reservation? or is it in populating Reservation table from Person/Company table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Yes, I want to know who did the reservation. I having a hard time in creating the relationship between the 3 tables I have.





Vonn Liquiran


As Kristen suggested you can use either of two
For first approach you might need a check constraint. But this is not very scalable as in future if you want to associate a third type of client you need to add a third column and alter check constraint.
The second method is more scalable as any new client type means a new item added in relationship table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

TheOxblood
Starting Member

19 Posts

Posted - 2011-09-18 : 06:03:27
quote:
Originally posted by visakh16

quote:
Originally posted by TheOxblood


quote:
Originally posted by visakh16

sorry not fully clear
Is the question to get associated company/person who did reservation? or is it in populating Reservation table from Person/Company table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Yes, I want to know who did the reservation. I having a hard time in creating the relationship between the 3 tables I have.





Vonn Liquiran


As Kristen suggested you can use either of two
For first approach you might need a check constraint. But this is not very scalable as in future if you want to associate a third type of client you need to add a third column and alter check constraint.
The second method is more scalable as any new client type means a new item added in relationship table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Thanks! I got both of you! :) So that it would be easier for me in adding a new type of Client! :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-18 : 08:13:50
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -