Groups | Blog | Home
all groups > sql server (alternate) > july 2003 >

sql server (alternate) : Small problem


versteijn NO[at]SPAM 538mail.nl
7/4/2003 5:10:29 AM
Hello

I have a case where Partners are some kind of Super-Users and are
stored in a SQL Server database. Best is IMO to put both in the same
table:

table Customers:
CustomerID[pr.key]
[blabla]
PartnerID

But of course I have to reference the partnerid from another table and
I want SQL Server to maintain the integrity rules. I could split
Customers en Partners into different tables, but that would not be
wise i think.

Or I could just reference the CustomerID from the other table and
-know- that we are talking about a partner, but in that case it it
possible to reference a customer that is not a partner, and i want to
avoid that.

Any ideas?

David R Rawheiser
7/4/2003 9:21:54 AM
The wonders of views ...

Create a view called Partners and have it select only the partners from
Customer.

That way in your other sql you can reference the view and then not have to
make sure the critieria to only show partners is included.

Going further you may want to have you table called Person and have two
views - Customers and Partners - that select from the same table, but with
different criteria (and perhaps columns in the result set).

Make sure the SQL in the view is optimized (i.e. the columns refered to in
the where clause are properly indexed).

[quoted text, click to view]

Erland Sommarskog
7/4/2003 10:40:25 PM
Versteijn (versteijn@538mail.nl) writes:
[quoted text, click to view]

You could have two tables. One main table with the Customers, including
partners. And then a subtable with the partners only. This permits
tables where only partners are allowed to have referential integrity to
that table only.




--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button