Relationships in MDS - sql-server

I have a question, with regards to how do you create the relationships between members of two different entities?
For example, in case of 1:1 you can create a domain-based attribute that is referencing the entity.
But in case you have a customer with multiple addresses, and you have an address entity.
When you update the member of the Address attribute of the Customer entity, based on the 1:M how would we be able to surface that relationship and connect the Address entity to the Customer entity?
So in case an Address member in the Customer entity changes, how would that update process work since we don't have a mapped relationship?
I know in M:M you would use a bridge table. And in the MDS database which table would contain that relationship info?
Any suggestions to articles and blog posts/Videos or ideas, would be greatly appreciated.
Thanks,
Andrea

In MDS (Master Data Services), you can use the Hierarchy feature.
- Option 1: create Explicit Hierarchy
If you're using SQL Server 2012 (possibly 2014 too), then an Explicit Hierarchy will solve this.
(see: Explicit Hierarchies (Master Data Services) )
Basically, you will be able to use Customer entity rows as parent nodes in the hierarchy (think of a tree structure) and assign one or more Address entity rows as child of each Customer.
As the name suggests, this needs to be "explicitly" managed.. means either someone will do this manually (drag-drop) using the MDS Hierarchy UI page or you can use an SSIS package to automate it while loading the staging table.
(see: Move Explicit Hierarchy Members by Using the Staging Process (Master Data Services) )
NOTE: Explicit Hierarchies have been Deprecated (starting SQL 2016 ...I think)
- Option 2: create Derived Hierarchy (bridge table- M:M)
This is similar to the bridge table concept that has been suggested earlier for M:M relationship, but in the MDS context.
Create another entity, call it CustomerAddressRelationship (let's say), let's call it CAR for now.
Add 2 Domain Attributes to CAR: one referring to the Customer entity, the other to the Address entity.
Now, if you want, you can create a Derived Hierarchy on this CAR entity in the format CAR > Customer > Address.
Read more about Derived Hierarchies: Many-to-Many (M2M) Relationships
- Option 3: create Derived Hierarchy (1:M)
Don't create CAR. Just add a column CustomerID (let's say) to the Address entity. This way every Address may have 0 or 1 Customer related to it.
Create a Derived Hierarchy for 1:M Relationship
Hope this helps.

Related

Differentiation between 'Entity' and 'Table'

Can someone tell me the easy way to explain the differentiation between an entity and a table in database?
Entity is a logical concept of relational database model. And table is used to express it, but there is a slight difference. Table expresses not only entities, but also relations.
For example, assume that you want to make a database of projects and employees of a company. Entity is a unit of information that has meanings by itself. In this case, there will be two entities - "Project" and "Employee". Each entity has its own attributes.
In relational DB model, there is another idea, 'relation'. If employees participate in several projects, then we can say that there is a relation with a name 'works_on'.
Sometimes, relation can have its own attribute. In this case, 'works_on' relation can have attribute 'start_date' and so on. And if this relation is M:N relation(Like this case: In project 1, there are 5 employees. Employee A works on two projects.), then you have to make an extra table to express this relation. (If you don't make an extra table when the relation is M:N, then you have to insert too many duplicated rows into both 'Project' and 'Employee' table.)
CREATE TABLE works_on(
employee,
project_id,
start_date
)
An entity resides in a table, it is a single set of information, i.e: if you have a database of employees, then an employee is an entity. A table is a group of fields with certain parameters.
Basically everything is stored in a table, entities goes into tables.
In a relational database the concept is the same. An entity is a table.
In OOP (Oriented Object Programming) there is a nice article in Oracle docs:
In general terms, entity objects encapsulate the business policy and
data for
the logical structure of the business, such as product lines,
departments, sales, and regions
business documents, such as invoices, change orders, and service
requests
physical items, such as warehouses, employees, and equipment
Another way of looking at it is that an entity object stores the
business logic and column information for a database table (or view,
synonym, or snapshot). An entity object caches data from a database
and provides an object-oriented representation of it.
Depending on how you want to work, you can create entity objects from
existing database tables (reverse generation) or define entity objects
and use them to create database tables (forward generation).
There is little difference between an entity and a table, but first we should define the concepts of “tuple” and “attribute”. I want to express those concepts with a table.
Here is an example of a table. As you can see it has some columns. Each column represents an attribute and each line represents a tuple(row). This is the employee table. In this example, the table is being used for representing an entity which is employee. However, if we create a new table named superior to specify the superiority relationship between those employees, it would be a table that represents a relation. In summary, we can use tables for representing both the entities and relations so entities and tables are not the same.

TPT entities derived from TPH base classes in Entity Framework 6?

I have a project that is using EF6 Database first mapped to a SQL database. This is all new so I control the EF model as well as the database schema.
I currently have a table that I'll call Vehicle for simplicity. I use a discriminator column to get subclass Entities Car and Truck. This all works fine.
Now I need to do a 'soft delete' and move any deleted vehicles to a VehicleHistory table. (After trying this w/ EF i will probably use a SQL transaction). This needs to be reviewable so I need this history table mapped as well, but I would like to keep it within the inheritance hierarchy so its easily reused in other classes.
My idea was to create 'vehiclecurrent' and 'vehiclehistory' tables with FK's to Vehicle for shared columns. i would then use TPT in EF to get 'carcurrent','carhistory', ect... derived from my TPH classes(so e.g. carhistory->car->vehicle). This is not working and I get Error 3034: "Entities w/ different keys are mapped to the same row"
So my question is basically how can I pull this off? Will this approach work and how, or is there another way to accomplish this? Thanks!

Database: Relation between one attribute to several entity instances

Is there such a thing? I'm not implementing anything, I'm just creating an E-R Diagram from it. Here is a simple example:
ENT(Ent_ID, Group_IDs)
GROUP(Group_ID, Att)
The attribute Group_ID would have an one-to-many relationship with different instances of GROUP. (Is the word instance correct here?)
P.s: I know I could create a third entity with Ent_ID and Group_ID as attributes to make the relations if I was implementing it, but I don't know if this has to be specified in the diagram.
The way I understand your example, you have a one-to-many relation:
Each GROUP instance can have many ENT instances related, but every ENT instance is related to one and only one GROUP instance.

Salesforce - Can a junction object be referenced as a parent of other object with master-detail relationship?

I have a junction object, "Purchase", with two master-detail relationships. One with Customer and another with Product. Now I need to add a master-detail relationship in Payment object with Purchase as a parent.
The problem is that when I try to create a new master-detail relationship the Purchase object is not available to select as a parent. I can do a Lookup relationship but not a master-detail.
Anyone know if there is a way of doing that or if there is a Salesforce limitation on that?
This is a Salesforce limitation. Unless an object is a master in all of its master-detail relationships, it can only participate in two master-detail relationships. In your case, you can get around this issue by converting any one of the three relationships on Purchase to a lookup relationship. Fortunately, new features in the Summer 12 release allow you to set lookup relationships as required and to perform cascading deletes on required lookups. If you were to set up on of the lookups in that way, the main piece of functionality that you would lose would be the ability to create roll-up summary fields on whichever object is no longer as master.

Shared Entity in one to many database relationship

I have a database I'm working on the design for. I have manufacturers and I have distributors on separate tables containing practically the same information with few exceptions. Both groups have one-many contacts that need to be connected to them. I created a contact table to hold contact information, one!
Do I need a second contact table? I'm trying to make this as DRY as possible. How would that look? Thank you in advance
Maybe a case for the party-role pattern? Manufacturer and Distributor are roles played by Parties. Contacts apply to Parties, not the role(s) they play. So you'd have:
a table named Party
a table named ContactMethod (or similar)
a 1:M relationship from Party to ContactMethod
which would resolve the need for two Contact tables. How you model the roles side will depend on wider requirements. The canonical model would have:
a single supertype named Role
a M:M relationship from Party to Role
a subtype of Role for each specific role (Distributor and Manufacturer in your case).
(Note: as an aside, this also allows a Party to play both manufacturer and distributor roles - which may or may not be relevant).
There are 3 'standard' patterns for implementing a subtype hierarchy in relational tables:
table for entire hierarchy
table per leaf subtype
table per type
(1) would apply if you don't have any role-specific relationships. (However I suspect that's unlikely; there's probably information related to Distributors that doesn't apply to Manufacturers and vice-versa).
(2) means multiple relationships from Party (i.e. one to each role subtype).
(3) avoids both above but means an extra join in navigating from Party to its role(s).
Like I say, choice depends on wider reqs.
hth.

Resources