Search code examples
umldiagram

How to indicate insert into DB in a diagram?


My situation is that I need to make a diagram that will show an endpoint and which tables the endpoint inserts data into, but i'm not sure how to do it.

My exact use cases will be the following:

  1. Insert one row into one table
  2. Insert multiple rows into one table
  3. Insert different rows into different tables (e.g. one row into users and one row into companies
  4. Insert multiple rows into multiple tables (e.g. two rows into users and two rows into companies

How would I show this in a diagram?

What am I trying to achieve?

To make a long story short (and spare you from some boring details), I've been building a table and an endpoint to store some data in that table. After some back and forth with the designer, the frontender and some more people, I've had to change both the table layout, the logic and output of my endpoint. This has all been due to (as I see it) bad planning of the task and missing clearity on which data is needed and where is saved (e.g. which data goes into which tables).

This has been a huge waste of time, so now I want to be better prepared for future tasks, by building a diagram that will show exactly which data goes to which tables. To do that I need to know how to show database CRUD actions in a diagram.


Solution

  • Before looking at UML

    The problem that you describe is very frequent. And even with a perfect diagram, you will not be able to completely avoid it. In fact, it is not a problem but a fact of life:

    • You need an efficient communication between endpoint developber, frontender, designer, and ... user.
    • Misunderstandings and expectations that are not clearly told by the users are as frequent as stars in the sky.
    • Before starting very tedious work, try to make sure there is a common understanding. Perhaps just with the table on a white board, and simulating on the board what will happen in different scenarios.
    • Another alternative is to make a quick simplified prototype. But this requires more effort.

    This approach will allow everyone to understand what the other mean, and result in a solid ground before starting the real effort. People can still change their mind, but at least it will not be because they misunderstood.

    Can a diagram help?

    Yes a diagram can help. But diagrams, like any language, may mislead or may be misunderstood. So, the diagram will help only if you take the time to explain it and discuss it.

    What UML diagram to use?

    It will probably be two diagrams:

    • the tables and their content will be represented in a class diagram. Class-diagram focus on the kind of objects that are managed by the system and their relationships. While objects have attributes and operations, tables will be represented with classes having only attributes. This article explains how to tailor ULM to database table design. So the focus will be on what should be in each table.
    • a behavioral diagram will explain what happens, for example when an end-point gets some requests. A popular one is the sequence diagram, where a lifeline will represent your end point, and you may use either a lifeline for the DBMS or a lifeline for the involved objects and tables. Here you can find an example showing tables in a sequence diagram. The focus of this second diagram is on how the tables will get managed.