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 2005 Forums
 Transact-SQL (2005)
 Some advice on my tables organization scenario

Author  Topic 

masteripper
Starting Member

25 Posts

Posted - 2010-07-29 : 03:04:51

I am planning for a project and i would like to have my tables like These:


The Clients Table
ClientID Name
1 Client1
2 Client2
3 Client3
...........
N ClientN

The Suppliers Table
1 Supplier1
2 Supplier2
3 Supplier3
.............
N SupplierN

And the Banks Table
1 Bank1
2 Bank2
3 Bank3
............
N BankN

Now the Info On which Client/Supplier uses which bank
Note C for Client ,S for Supplier
ClientSupplier BankID
C1 2
C1 3
S2 1
S3 2
And so on....

Consider that there should be a separate form for the Client and one for the Supplier .On each of these forms i should have a datagrid for entering the bank information.
I could easily have a Clientbank and a SupplierBank table but i want to know if this scenario can work.

Kristen
Test

22859 Posts

Posted - 2010-07-29 : 03:19:59
How about separate tables for ClientBank and SupplierBank - i.e. the tables which link clients / suppliers to banks.

Presumably a Client may use more than one back? if not just add a BankID column to the Client table. Same for Supplier.

Do NOT combine the ClientID with a "C" on the front (as per your final example), at the very least use a separate column for "Source" - i.e. "C" or "S".

But that means that you can't then easily put a Foreign Key relationship on the ID column to join it back to the correct table.

If you want a single Client / Supplier Bank Link table then you could make two table, one for each (as I described above) and then create a VIEW that combines them together (with "C" or "S" [Source] indicator too)
Go to Top of Page

masteripper
Starting Member

25 Posts

Posted - 2010-07-29 : 03:33:12
So it is much better to create two separate tables one for clients and one for suppliers.
On the other hand considering the scenario of separate column for the "source" how could it be possible to put a foreign key relationship.
The idea of the view is good but it falls to the case of 2 tables....so ...
I'd like to say that this is something i am thinking as a way to reduce "unnecessary" tables ......i know it is strange and probably it would cause more problems than solve other but it was spinning in my head for some time and i would like to know all possible approaches
Thanks for the quick response and i am waiting for some more
comments.
P.S
Consider the case that could easily have a lot of of "sources" and "related"
Something like this

SomeComplexID..... Related
CS001.............. 1
CS001.............. 4
CS007.............. 1
CS008.............. 9
CE008............. 18
DR008............. 23
AS038.............. 9
and so on

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-07-29 : 11:55:47
A couple of suggestions, First, if you have not read an Introduction to Database Systems, I'd suggest you read it (I suggest everyone who touches a database read it ).

Second, Surrogating could/might be considered bad, but SQL is very good at it. So, it can be a powerful technique. But, generating "IDs" based on an entity it comes from is most definitely a bad idea. As Kristen suggested, creating a relationship table is the way to go. That will Relate Entities to other Entities without having to create functional dependencies and make it much easier to properly constrain your database.
Go to Top of Page
   

- Advertisement -