Showing posts with label relational. Show all posts
Showing posts with label relational. Show all posts

Wednesday, March 21, 2012

Number of foreign keys

I understand the number of foreign keys allowed is restricted by the DBMS I
use.
In a general relational schema design perspective how many foreign keys a
table shall have?
If I have large number of foreign keys what anamolies it will lead to?
Is this crucial to identify all the foriegn key relationships for a table?

VinodhOn Thu, 2 Dec 2004 13:06:57 +0530, Vinodh Kumar P wrote:

>I understand the number of foreign keys allowed is restricted by the DBMS I
>use.

Hi Vinodh,

For SQL Server 2000 (and 7.0), this limit is 253 foreign key table
references per table. I can't imagine any serious application ever
exceeding this limit.

>In a general relational schema design perspective how many foreign keys a
>table shall have?

Depends. Some tables will have only one or none, other tables might have
more (sometimes evemn much more) foreign keys. There is no general answer,
just as there is no single "one-size-fits-all" database design. That's why
requirements analysis and normalization are the most important stteps in
database design.

>If I have large number of foreign keys what anamolies it will lead to?

None - fooreign keys PREVENT anomalies, as the database will check all
changes to the data to make sure the constraint is not violated. This will
slow down the processing of insert, update and delete statements, though
not by much (if you use proper indexes).

>Is this crucial to identify all the foriegn key relationships for a table?

Yes. Unless you like cleaning up corrupted data. <g
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Saturday, February 25, 2012

Null Processing and RowCounts

Problem: Although my query against three relational fact tables correctly returns the basic truth that "RowCount All_Transaction table" = "RowCount Loan table" + "RowCount Sale table", my cube-browser query rowcounts in these tables' resulting cube shows (incorrectly) that "RowCount All_Transaction table" = "RowCount Loan Table" ...and I'm scratchin' my head about why! Note: I'm on SSAS2005 SP2, Dev Edition

Background:

DSV -- Fact Tables:

(1.) All_Transaction: Contains generic facts (dates, asset info, etc.) on two types of asset transactions (sales and loans). In DSV, it is is directly related to each of the next two fact tables.

(2) Loan: Contains loan-specific facts (loan amt, etc.) for loan transactions. Does not directly connect to Sale fact table.

(3) Sale: Contains sale-specific facts (sale price, etc.) for sale transactions. Does not directly connect to Loan fact table.

Additionally, DSV table relationships from all_transaction to other two has all_transaction as "Destination / PK" and other table as "Source / FK" table, which is in keeping with relational rule that all FK's must relate to one PK. Lastly, with regard to relational and DSV fact tables, cardinality is actually one-to-one, since each row in LOAN (or SALE) table relates to exactly one row in All_Transaction.

Cube Measure Groups:

Of course, all three fact tables are measure groups. ALL_Transaction and LOAN fact tables are also reference dimensions, with dimension cardinality to each other's measure group set as "One". This was done to allow slice-n-dice by dimensions, all of which are connected to just those two measure groups.

Anybody have ideas on why this is occurring, and what to do about it?

Note: My relational SQL-Dev coworker suggests it sounds like a "left-join vs. inner join vs. right join" issue and/or an issue of which measure group is the "main" measure group", but I don't know that these ideas apply to SSAS.

Your thoughts?

I'm going to close the loop by answering my own question...

Reason for Problem:

The reason is that, (1) I was using the "ALL_Transaction" fact table also as an intermediate dimension for "ALL_Transaction" - related dimensions indirectly referencing "LOAN" fact table, and (2) I had selected "unknown member" for null properties on the dimension key for "ALL_Transaction" intermediate dimension. As a result, the COUNT aggregation, by design, ignored all of the so-called "unknown member" ALL_Transaction PK's that don't have a corresponding LOAN table FK (by design, many don't).

Solution: On "ALL_Transaction" dimension key field, change "KeyColumn / Null Processing" property from "Unknown Member" to "Preserve". Simple (now that I found the solution).