Database Design – Handling Cyclic Relationships in ER Diagrams

database-designdatabase-diagramserd

I am trying to draw an generic entity-relationship diagram (ERD) to model a software object (Let's say a XML file). This XML file has references to other XML files. Also, if a XML file (say "file-A") is referred by another XML file (say "file-B"), then "file-B" cannot referred by other XML files.

If I need to model those relationships in an ERD, the source entity and the target entity becomes same. I want to know whether this is acceptable or not? Because, if it is acceptable, specifying cardinality becomes an issue as different readers interpret the cardinality in different ways:

  1. Eg – an XML file can have references to zero or more XML files
  2. Eg – an xml file can have only one reference to another XML file

enter image description here

Best Answer

Yes it is acceptable. In ER modeling, this is known as a reflexive relationship. In a relational model, it's implemented by a foreign key that references another row in the same table.

The simplest example is a table of employees, where the PK is EmployeeID (or just ID) and there is an FK called SupervisorID. This kind of thing is done all the time.