473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Small problem

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?

Freek Versteijn
Jul 20 '05 #1
4 1838
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).

"Versteijn" <ve*******@538mail.nl> wrote in message
news:4d**************************@posting.google.c om...
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?

Freek Versteijn

Jul 20 '05 #2
Versteijn (ve*******@538mail.nl) writes:
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.


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, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
"David R Rawheiser" <ra*******@hotmail.com> wrote in message news:<c4********************@comcast.com>...
Every index requires additional overhead when doing an insert or update on
the indexed column, but that is the price for the later search and retrieval
speed (you can't get something for nothing in this world).

Hopefully the keys being searched on won't change very often (how often do
you change someone from a partner to a customer?).

If the application does in-place updates the performance overhead should be
minimal.
if the application does delete and insert to update that obviously would be
more.

Benchmark it to see for sure.


Ok, thank you, I will.

One more question I forgot to ask you. This all started with searching
for a way to reference a non-key field (the PartnerID) of Customers
from a second table. Can I now refer to the PartnerID of the created
view? How can I do that?

Sorry, I'm new to the advanced techniques of SQL and SQL Server, but
I'm sure I can use all this knowledge in the future too :)

Thank you in advance

Freek Versteijn
Jul 20 '05 #4
Versteijn (ve*******@538mail.nl) writes:
One more question I forgot to ask you. This all started with searching
for a way to reference a non-key field (the PartnerID) of Customers
from a second table. Can I now refer to the PartnerID of the created
view? How can I do that?


If you mean by a FOREIGN KEY reference, I don't think you can. It could
be that this is possible if you index the view. I have no tested this,
but I would not expect it to work.

If you want a foreign-key constraint, then PartnerID must be the primary
key in its own table. As I said in another posting, this could be a
sub-table to the Customers table.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Brueck | last post by:
Below is some information I collected from a *small* project in which I wrote a Python version of a Java application. I share this info only as a data point (rather than trying to say this data...
2
by: Marek Malowidzki | last post by:
Hi all, I am writing a component that exposes a C++ library as a .NET component. The approach is somewhat automatic: every library C++ class has its managed C++ counterpart that keeps a pointer...
11
by: Bo Peng | last post by:
Dear List, It is not clear what the title means. :-) Here is the details: I need to manage a big bunch of small objects, like struct{ int a; int b; }obj;
0
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
2
by: Luc | last post by:
I saw a few posts on this newsgroup about it but nothing to help me resolve this problem: We designed a window in .NET on a platform using small fonts (120 ppp). But this window will run on...
4
by: =?Utf-8?B?VzFsZDBuZTc0?= | last post by:
When one architects a new project one of the first steps in the decision is to decide on the layers. (In my opinion anyway) One architecture that I have used before is to go solid OO and create...
12
by: elty123 | last post by:
I have a small C# program (about 400 lines of code) that is only 28kb after compiled. However when it runs (takes a whole 5 seconds) it takes up nearly 20MB of memory and I don't see why. ...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.