Create many to many relationship between facts - ssas

I have two facts tables facturesAvoirs and F_achat , How Create many to many relationship between facts?

Related

More than 50 different categories that share 50% of attributes. How to create all these tables efficiently in sql database? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
In large system, when analyzing the database, there are about 50 different categories in the requirements, which should represented as tables.
Each category has many attributes - columns-, all these categories has the same of 50% of columns. For example, each category has (id, name, date, state, admin, dept), all categories have those attributes, but each category has its own attributes which differ from each other, they are about 3 - 5 attributes.
Now, how to represent them in the physical database as tables? One table, or table for each category, what about redundancy?
Depends on what exactly you are trying to achieve.
If your primary concern is disk space, I would recommend to consider sparse columns, with column sets as an option, if necessary. In this scenario, you can put all these entities into a single physical table, with mandatory attributes being normal columns and specific attributes being declared as sparse.
If you are thinking about a normalised model which would eliminate most of data anomalies, a typical solution is a supertype-subtype hierarchy. The main table stores only the attributes that are mandatory for all entities, and child tables contain only main table' identifier and attributes specific to this particular category. All the child tables reference the "supertype" table via foreign keys.
Sometimes, depending on subject area, a more complex model with additional "nesting" levels might be employed. You can think of this as a class inheritance hierarchy - the analogy is very close, actually.
Of course, both (and other) approaches have their strengths and weaknesses, so you might need to read up on the subjects and make a choice.
As some attributes are only applicable to some categories, you can think of Entity-Attribute-Value model, for storing the categories.
There are multiple ways of representing EAV models in a database. You can refer to below article: https://inviqa.com/blog/understanding-eav-data-model-and-when-use-it
The EAV model way of data storage comes up with its own challenges, when you query the database. So, see whether it will suit your needs, before choosing the same.

Database design - single subtype in a separate table vs common table [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
In a food delivery app I have a USERS table that holds info about user data like firstname, lastname, email, password etc.
A small subset of users (~1% of all users) will have a delivery person role assigned. This means that there will be some delivery person-specific data like driver license id, average_rating and some more.
What I'm unsure of is what's better: have one USERS table that holds all the data (which means that for the majority of users the delivery-person specific columns will be null) or have a subtype table (DELIVERY_PERSON) that will hold those columns and a foreign key to USERS table?
Option #1
USERS:
id(PK)
email
password
name
...
driver_license_id (null for all regular users)
avg_rating (null for all regular users)
more delivery person specific columns
Option #2
USERS:
id(PK)
email
password
name
DELIVERY_PERSON:
id (PK, FK to USERS.id)
driver_license_id
avg_rating
more delivery person specific columns
I've seen several similar questions on SO, but in all of them there are multiple subtypes like Vehicle -> Car/Airplane/Boat etc.
In my scenario there is one base type (user) and only one possible extending subtype (delivery person). I'm wondering if having only one possible subtype somehow affects what option to choose.
The "clean" implementation of subtypes is, in my perception, to create a separate table for each subtype and a common one for the supertype.
This avoids complex integrity conditions and reduces the number of null values.
To illustrate how complex integrity conditions arise, just imagine you have a supertype and a subtype with 10 additional mandatory properties ("columns") and several optional properties.
Now if a single optional property is non-null, the 10 additional mandatory properties must be non-null as well.
This gets worse if you imagine you have 12 subtypes instead of just one.
On the other hand, if you store everything in a single table, you don't have to perform joins. This is a performance advantage that can add up if you often need the additional columns.
Naturally this is only partially true. If you have many subtypes, the rows will be long. This reduces the effectiveness of your data cache.
If your application doesn't need the additional information very often, it is probably better to keep a separate table for the additional columns. If it needs all the information all the time, you'll probably be better of with a single table containing everything.
In short: there is no general answer to your question.
The best approach will be to make a guess based on your application and my considerations. You then implement this and test if the performance of your implementation meets your requirements. If so, you have a valid implementation. If not, try the other strategy.

Many to many database design

I have Person and Course that have many to many relationship. (There is a table that maintains the relationship with just the 2 IDs
Is it better to have a 3rd boolean field Selected for that relationship.
Or add/remove the complete rows from the relationship table?
What is more common? I need to support editing as well
From the comments:
It's better to remove the rows from the relational table in order to save spaces, especially if you don't have any details on the relational table

Benefits of a join table? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am trying to explain the benefits of a join table to a colleague, and below is an explanation. Am I correct?
Currently he has the relationship between a pic and tag with two tables. A pic table and a tag table. The pic table has a tag_id this is a FK to an entry in the tag table. Here was my response:
First lets look at pics and tags tables. So in your current architecture lets imagine two pics (a & b). We tag pics a & b with the hashtag #wtf. We now have two entries in out tags table:
pic_id title
------ -----
a wtf
b wtf
Do you see the issue? So imagine we have 1000 wtf tags on a 1000 different pics. With this same architecture we now have a bloated tags table with all this repeated data (and wasted space). This issue arises when we have a many to many relationship. In this case many pics can have many tags, and many tags can have many pics. How would we fix this? The answer is a join table. So we create a new table. Lets call it pic_tag. This table would have columns pic_id & tag_id. So now new tables would look like:
pic_tag
pic_id tag_id
------ ------
a 1
b 1
tags
id name
-- ----
1 wtf
pic
id name
-- ----
a pic1
b pic2
So this does a couple of things for us. First it saves space. We only store the string 'wtf' one time. Second, to find all pics with the tag 'wtf' we first go to the tag table and find the id of 'wtf', then go to the pic_tag table and search for that id which is much more efficient that searching a bloated 'tags' table for a given text. Said another way, search for ints is much faster than searching for text.
The main benefit is that there are relationships that can only be modeled with a join table.
Say you have two entities A and B. If the relationship A:B is 1:1, the two can be represented by a single table. If A:B is 1:N (like 1 customer can have N orders but each order comes from only one customer), then you could model this as a foreign key from orders table to customers table. But if A:B is N:M (your tags scenario is a good example) you need a way to represent 0, 1 or N tags for each picture. There is no sound relational representation for that other than a join table.
Note you could represent multiple tags per picture while breaking some principles of relational design (like storing multiple tags or FK's to tags) in a single column. Whether to do that or not is a design decision.
Other benefits: you can change your mind whether the relationship is 0:1, 0:N, 1:(0-5), 1:N etc. without changing the core data model -- addressing that logic in triggers or application logic. You can create additional indexes to help with joins. You can introduce more uniqueness constraints to enforce data logic etc.
But the main benefit is, join tables are the only relationally sound way to model certain types of relationships.

What's the correct name for an "association table" (a many-to-many relationship) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What's the correct or most popular name for an "association table"?
I've heard lookup, associative, resolving, mapping and junction table.
There is no "correct" name, but the academic name would be an "Associative Table" (see See the Wikipedia article Associative Entity). Other common names are (in alphabetical order):
Association table
Bridge table
Cross-reference table
Crosswalk
Intermediary table
Intersection table
Join table
Junction table
Link table
Linking table
Many-to-many resolver
Map table
Mapping table
Pivot Table
Pairing table
Relationship table
Transition table
Note: This is contents original created by Derek Greer but that was posted as an edit to an accepted answer that totally changed the answer.
Cross reference table. CustomerProductXRef.
"Correct" depends on the modeling methodology in use. I am familiar with Chen, in which this table is the physical implementation of an Associative Entity. I suppose most popular would be directly related to most popular modeling methodology.
Wikipedia lists several names for this type of table.
I was taught and use the term "Join Table"
Depends on whom you ask. They're all correct, use the term that makes the most sense to who you're talking to.
Relationship table.
"One of the basic tricks in SQL is representing a many-to-many relationship. You create a third table that references the two (or more) tables involved by their primary keys. This third table has quite a few popular names, such as 'junction table' or 'join table,' but I know that it is a relationship."
Hollywood Couples by Joe Celko
Do you call your customer table CustomerTable or Customer or Customers? I generally use a "business object" name (eg Orders for information about which customers have ordered which products, not CustomerProduct) but a table that really just tracks the relationship, like SalesRepCustomer, I give the name of the two tables involved and don't add a suffix. As others say, be consistent.
I reserve the name lookup (in conversation, not in the table name) for things like "what is the name of Country 11", not for "which sales rep looks after Country 11".
We call these Crosswalk tables where I work. Naming is based on Table1XTable2 where the contents are the PKs of the 2 tables.