What is the name of the table where view modes are stored? We have 10 view modes that we created. When we run drush @env cex sync in our local we are able to export the config files related to these view modes such as core.entity_view_mode.node.related.yml (where related is the view mode).

Is there a database table where these View modes are stored? If so, what is the name of it?

We are not using Display Suite or Panels, just the out of the box View Modes from Core. We do not plan to add those modules. 

Goal:


Find out what view modes are being used programmatically.
Delete all view modes that are not being used. 


Definition of not being used:


Article content type has 3 custom view modes: listing, minimum, related
Basic Page content type has an Entity reference to Article pages where the Article view mode = listing under Basic Page Default View Mode.
Custom view modes listing and minimum are not being used. However, if we consider all content types (e.g. 10 more content types) then it will be a pain to have to go through one by one.
View modes are stored in the configuration entity entity_view_mode which you can load like any other entity:

$view_mode = \Drupal::entityTypeManager()
  -&gt;getStorage('entity_view_mode')
  -&gt;load('node.teaser');


To load all view modes for the entity type node:

$view_modes = \Drupal::entityTypeManager()
  -&gt;getStorage('entity_view_mode')
  -&gt;loadByProperties(['targetEntityType' =&gt; 'node']);


View modes don't store much data other than a label for the view mode name.

How a view mode is displayed for a specific content type is stored in a different entity:

$display = \Drupal::entityTypeManager()
  -&gt;getStorage('entity_view_display')
  -&gt;load('node.article.teaser');


The usage depends on how you define what being used means. If you mean with not used that it is not configured in a content type, which you can query in the config entities mentioned before, this doesn't mean necessarily, that the view mode is not used anywhere. If you configure an entity to be displayed in a view mode, for example in a View or a entity reference field, and this view mode is not configured in the content type, then it fallbacks to the default view mode.