ESRI parent/child relationship within the same table - relationship

Is it possible in ESRI to make a relationship within the same table or any other way to solve parent/child relationship? I have table “samples” and one sample can be split into multiple sub-samples which means any record(sample) can have one or multiple parents and opposite. But as parent and child represents the same thing they should be a member of the same table. Any ideas would be appreciated!
I have tried creating intermendiate table 2 relationship class
Relationship class 1:1 Simple where sample.id=intermediate.sample_id
Relationship class 1:M Simple, sample.id=intermediate.sample_initial_id
But it ended up that I have to delete the relationship record in intermediate table before deleting parent or child otherwise there will be written in intermediate table. Its not very comfortable and I don´t know how it would work in services.

One approach would be to use a self-join on the table. This involves creating a copy of the table and joining it back to itself using a foreign key to establish the parent-child relationship. In your case, you could create a "parent_id" field in the "samples" table that references the "id" field of the same table. Then, you can join the "samples" table to itself using the "parent_id" field to establish the parent-child relationship.
Another approach would be to use a hierarchical relationship class. This type of relationship class is designed to handle hierarchical data, such as parent-child relationships, and can be used to maintain relationships between records in the same table. In this case, you would create a hierarchical relationship class that defines the parent-child relationship between records in the "samples" table.

Related

ERD 3 tables in 1 relationship

i am having a hard time creating an ERD for my table relationship. I have 4 tables: film, ticket_type, studio, and schedule. The schedule table is a relationship table that contain the primary key from the other three tables as foreign key. The question is how can i picture it in ERD? Something like many-to-many relationship but with 3 table, is it possible to do it like this? The database works fine when i try to create it so i think there's​ no problem in my concept. Thanks in advance.
Edit: forgot to add the ticket_type table is for pricing and type like: 2d,3d,or 4d, i create it like this to avoid redundancy.
One more question, can i add another field to a relationship table? If I remember correctly it should be fine, but just to make sure.
If schedule is a relationship, it would be represented as follows on an entity-relationship diagram:
Relationships are identified by the keys of the related entities. A table diagram makes this more visible:
However, if schedule is an entity set with relationships to the other 3 entity sets, it would be represented as follows on an ER diagram:
If we map every entity set and relationship to its own table, we get the following table diagram:
However, if we denormalize the relationship tables into the schedule table (since they all have the same primary key), our table diagram changes to:
Compare this with the first table diagram. While these physical models are very similar, they derive from very different conceptual models. Strictly speaking, I think both "entity table" and "relationship table" are inappropriate for the denormalized schedule table. In the network data model, we would call it an associative entity (but that's not the same as associative entities in the ER model).
Finally, relationships can have attributes too:

Unable to use the dimension table as a nested table in SQL server data tools

I have the following relationship set up between my fact table and dimension tables.
When trying to create a data mining structure, I had to choose the dimension table Dimension_Status as a nested table for the fact table as I'm trying to predict the probability of "TimelyResponse" in the fact table using the "IssuedVia" in the Dimension_Status table. But when trying to do so, I get the following error.
Dimension_Status table cannot be used as a nested table because it does not have a many-to-one relationship with the case table. You need to create a many-to-one relationship between the two tables in the data source file
What am I doing wrong here? Why am I getting this error though my dimension tables are maintaining a many to one relationship with the fact table? Please advice.
I could be completely missing the mark here (I haven't done a great deal of data-mining using SSAS), but from what I can tell nested tables are the "Many" side of a many-to-many relationship. From the MSDN article on Nested Tables it shows the "Products" table as being nested in the "Customer" table, because each Customer can have many Products:
In this diagram, the first table, which is the parent table, contains
information about customers, and associates a unique identifier for
each customer. The second table, the child table, contains the
purchases for each customer. The purchases in the child table are
related to the parent table by the unique identifier, the CustomerKey
column. The third table in the diagram shows the two tables combined.
A nested table is represented in the case table as a special column
that has a data type of TABLE. For any particular case row, this kind
of column contains selected rows from the child table that pertain to
the parent table.
So it looks like nested tables are not what you're after - unfortunately I'm not familiar enough with the SSA data mining tools to recommend the appropriate approach (unless switching them around and making the DimStatus table your Case table and Fact_CustomerComplaints your Nested table will work in your situation.)
To put it simply, your arrows are backwards.
Reverse the relationships so the tables you want to be nested are pointing to your Fact_ table.
Like so:

Adding junction table to EF ends up as association

I have couple of tables and a junction table in between.
AspNetUsers and Tenant tables are already added in my Entity Framework.
But once I add UserTenant table, it ends up as association instead of entity.
Can someone enlighten me why this happens?
This happens because the only function of this junction table is to create a many to many relation.
When EF finds a table which only have columns which are FKs to other tables, and they compose the primary key, it simply converts it to a many-to-many relation.
If you need to have access to the junction table, you ned to break that rule. The easiest way to do so is adding a new column to the junction table which is not part of an FK, neither the PK. If you do so, the junction table will become an entity in your model. But you will lose the easy way to navigate to relate entities (it's still possible, but a bit harder). See this for more details
You can also read this article, which offers an alternate way of doing this, if you use Code First. If you read it, don't miss the comments. There are several very interesting

Implementing tree in a database with child having more than one parent

I've table with fields Id,Name,ParentId(Id) & Leaf. I want to model tree like structure where child/element with Leaf=1 can have more than more parent. How can I model this situation in this table or do I need an extra table to handle this thing. I want this modelling for implementing Tags like in Stack overflow.
You'll need another table, unless "more than one parent" has a smallish upper limit, in which case you can add ParentID fields for the number of possible parents, but this is not recommended.
You appear to have a many-to-many relationship. This can be modelled as below:
Entity table
ID (Primary Key)
... - other entity fields
Parents table
ChildID (Foreign Key - Entity.ID)
ParentID (Foreign Key - Entity.ID)
The Leaf=1 entities being the only ones allowed to have multiple parents is a constraint that is best handled on a code level, or possibly with database triggers.
It doesn't seem possible to enforce this directly without creating another table (a third one) (which will contain all entities with Leaf=1, either linking to an Entity entry or having the row defined only there, though I would not advise either - it's messy and not the type of constraint you design your database around).

on what basis relationship between tables are defined

I have a question, if two tables in database are from different entities then how we define relationship between them. i mean can we use some foreign key or any thing to define relationship between them. or we have to create a third table
It depends on what kind of relationship you have. If it´s a 1-1 or 1-N then you will only add foreign key column on the respective table. If you need a N-N (aka N-M) you will need a third table.
There is a design principle that states that a table either defines an entity or a relationship but not both. Therefore, use a third table to model the relationship between your two entities -- yes, even if it is 1-1 or 1-N -- noting that the relationship itself may have its own attributes.

Resources