Click here to Skip to main content
16,010,392 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL server nested tables or what? Pin
iskaza21-Sep-06 14:22
iskaza21-Sep-06 14:22 
GeneralRe: SQL server nested tables or what? [modified] Pin
Rob Graham21-Sep-06 14:43
Rob Graham21-Sep-06 14:43 
QuestionOne more question Pin
iskaza21-Sep-06 15:12
iskaza21-Sep-06 15:12 
AnswerRe: One more question Pin
Rob Graham21-Sep-06 17:36
Rob Graham21-Sep-06 17:36 
QuestionRe: One more question Pin
iskaza22-Sep-06 3:00
iskaza22-Sep-06 3:00 
GeneralDesign question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 5:47
sponsorJudah Gabriel Himango21-Sep-06 5:47 
GeneralRe: Design question - returning varying results Pin
Eric Dahlvang21-Sep-06 6:42
Eric Dahlvang21-Sep-06 6:42 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 8:35
sponsorJudah Gabriel Himango21-Sep-06 8:35 
EricDV wrote:
Judah Himango wrote:
- create a view that returns all possible data for all 15 or so tables?

I tend to not like this kind of stuff. It usually looks like a mess, is not easily scaleable, and is difficult to maintain. You have to remember to change the view whenever you add a new FooInheritor type.


We initially used this solution, only to find out it is a mess (views returning some 30 fields or more! Ugh!) and a pain to maintain (every time you add a new Foo type or change an existing one, you have to update the view accordingly! Ugh!).

EricDV wrote:
This is probably easiest to write, along with keeping things normalized. But, two queries aren't as fun as one.


This is the cleanest solution from the consuming code side (C#) where I can still keep everything as objects. It just requires lots of sub-queries.

Let me explain my situation a little more: these tables are queried frequently. I expect something between 5 and 100 rows to come back, although there is no hard-coded limit right now.

Each row returned is a Foo instance, but it could be a regular Foo, a FooInheritor, or a AnotherFooInheritor. Going with the clean solution, it would look like this:

FooRow[] rows = fooTable.GetResults(); // Query #1!
for(int i = 0; i < rows.Length; i++)
{
   Foo theFoo;
   if(rows[i].Type == Foo)
   {
      theFoo = new Foo(rows[i]);
   }
   else if(rows[i].Type == FooInheritor)
   {
      theFoo = QueryFooInheritorTable(rows[i].ID); // Another query!!
   }
   else if(rows[i].Type == AnotherFooInheritor)
   {
      theFoo = QueryAnotherFooInheritorTable(rows[i].ID); // Another query!!
   }
   ... // and so on
}


What I'm worried about is performance. If I'm returning 100 results, I can potentially make 101 queries: 1 query to the FooTable, then another query for each row returned if that row is FooInheritor, AnotherFooInheritor, or some other type that inherits from Foo.

What do you think?



Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul

Judah Himango


GeneralRe: Design question - returning varying results Pin
Eric Dahlvang21-Sep-06 11:23
Eric Dahlvang21-Sep-06 11:23 
GeneralRe: Design question - returning varying results [modified] Pin
Eric Dahlvang22-Sep-06 3:26
Eric Dahlvang22-Sep-06 3:26 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango22-Sep-06 5:38
sponsorJudah Gabriel Himango22-Sep-06 5:38 
GeneralRe: Design question - returning varying results Pin
Eric Dahlvang22-Sep-06 6:17
Eric Dahlvang22-Sep-06 6:17 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango22-Sep-06 6:28
sponsorJudah Gabriel Himango22-Sep-06 6:28 
GeneralRe: Design question - returning varying results Pin
Scott Serl21-Sep-06 7:49
Scott Serl21-Sep-06 7:49 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 8:39
sponsorJudah Gabriel Himango21-Sep-06 8:39 
GeneralRe: Design question - returning varying results Pin
Scott Serl21-Sep-06 9:03
Scott Serl21-Sep-06 9:03 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 10:00
sponsorJudah Gabriel Himango21-Sep-06 10:00 
GeneralRe: Design question - returning varying results Pin
Scott Serl21-Sep-06 10:27
Scott Serl21-Sep-06 10:27 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 18:01
sponsorJudah Gabriel Himango21-Sep-06 18:01 
QuestionRowFilter and Dataset Pin
Itanium21-Sep-06 2:28
Itanium21-Sep-06 2:28 
AnswerRe: RowFilter and Dataset Pin
Stephan Pilz21-Sep-06 21:06
Stephan Pilz21-Sep-06 21:06 
QuestionVisual Query Builder Pin
BadKarma21-Sep-06 2:09
BadKarma21-Sep-06 2:09 
QuestionSQL Server CURSOR Pin
choorakkuttyil21-Sep-06 2:07
choorakkuttyil21-Sep-06 2:07 
AnswerRe: SQL Server CURSOR Pin
_AK_21-Sep-06 3:34
_AK_21-Sep-06 3:34 
AnswerRe: SQL Server CURSOR Pin
Eric Dahlvang21-Sep-06 3:45
Eric Dahlvang21-Sep-06 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.