EDR M:N relationship with multiple dependencies - database

I am in process of designing a reporting tool. the Interface will be C# with backend database. The tool will allow to enter and edit data through an interface and save it to the Database. Additionally, it will provide specific reports, based on the data retrieved from DB.
Currently, I have been trying to solve a M:N relationship in for my DB tables.
The tool lets a user to enter daily Item amounts (Steel and Mesh) based on a Project. I have solved the M:N relationship in the following diagram but I am not sure if this is actually possible and whether I need to break down the daily stats table further, due to a composite key containing 4 PKs from other tables. This is the current diagram i got.
I am wondering whether the diagram has solved the M:N relationship correctly and whether there is a better way to utilise the date table.

Related

How to persist data in microservices?

I am getting started in microservices architectures and I have a couple of questions about the data persistence and databases.
So my understanding is each microservice has it's own database (not necessarily, but usually). But given that case, consider a usual social media platform with users, posts and comments. There will be two microservices, a user's microservice and a posts' microservice. The user's database have a users table and the posts' database has posts and comments tables.
My question is on the posts microservice, because each post and comment has an author, so usually we would create the foreign key pointing to the user's table, however this is in a different database. What to do then? From my perspective there are 2 options:
Add the authorId entry to the table but not the foreign key constrain. If so, what would happen in the application whenever we retrieve that user's data from the user's microservice using the authorId and the user's data is gone?
Create an author's table in the posts' database. If so, what data should that table contain other than the user's id?
It just doesn't feel right to duplicate the data that is already in the user's database but it also doesn't feel right to use the user's id without the FK constraint.
One thing to note, data growth is quite different
Users -> relatively static data.
Posts & Comments -> Dynamic and could be exponentially high compared to users data.
Two microservices design looks good. I would prefer option-1 from your design.
Duplication is not bad, In normal database design this is normal to have "Denormalization" for better read performance. This is also helping in decoupling from users table , may help you to choose different database if require. some of your question what if users data is missing and posts is available, this can be handle with business logic and API design.

hybris - one to many and many to many relationship

In our production sytem, we have an existing relationship which is one to many. We would like to change this relationship to many to many due to business/data reasons.
What steps we need to take without loosing data and with no impact to production data, as we need to change *-items.xml file within hybris system.
Appreciate your inputs.
Thanks!
The database structure for one-to-many and many-to-many is different. One-to-many records uses 1 table (the many records are saved in the one table), but many-to-many uses an extra table.
I suggest to export existing data, update the items.xml (with platform update), and reimport the data.

Aggregating all relations into one table SQL Server

I'm trying to design an enterprise level database architecture. In ERD level I have an Issue.
Many of my tables have relations which each other. there may be some developments in the future and my design should be flexible and also fast on gathering the results.
In recent days I have created a Parent Table which is named Node and all of my Functional Tables has an one-to-one relation with this table.
(Functional Tables are those who keep real life datas like Content, User, Folder, Role, .... and not those who related to applications life-cycle)
So before adding a record to each table, We must add a Node into the Node Table and take the new NodeId to add into secondary table.
Node table alone, has a Many-To-Many relation with itself. so I designed this table to keep whole of my relation concerns.
All of the other entities are like the User and are related to the Node table as shown above.
Problem is: Does this design makes my relational queries faster on NodeAssoc table or It's better to keep relations separately ?
You say:
There may be some developments in the future and my design should be flexible and also fast on gathering the results.
Flexibility and performance are two separate things. Which have different ways to approach them or solve them. When you are designing a database, you have to concider database principles. Normalization is very important to keep in mind. Relations one-to-one and many-to-many are by design not common. In your case you are mentioning one-to-one and many-to-many relations, on which I have my worries.
Advice one -> Denormalize (merge) one-to-one tables to one table.
This reduces the amount of joins.
Advice two -> Introduce a bridge table on many-to-many table,
because there could be multiple matches. Fixing multiple matches means
complex queries, which leads to performance drop.
Advice three -> Use proper indexes in order to improve the performance
Increasing of flexibility can be through using Database Views, which is a query. The structure of the database may change in the future, while modifieing the view can be very fast too.

Relational model of database management system

Instead of having separate relation what if the problem of having one big relation that will store all the data related to a system?
A single database may not fulfill all the needs of a complete system. For example : Lets take a ecommerce website. Here you have following important things :
Customer Information
Order information
Inventory Information etc.
Now if you see these three are not related to each other other than that they are all a part of ecommerce system. You don't need to store the user information along with inventory information in a single table as they are not related.
After this part is answered, Now, you can have doubts so as to why we need normalization. The objectives of normalization as mentioned here are:
To free the collection of relations from undesirable insertion, update and deletion dependencies;
To reduce the need for restructuring the collection of relations, as new types of data are introduced, and thus increase the life span of application programs;
To make the relational model more informative to users;
To make the collection of relations neutral to the query statistics, where these statistics are liable to change as time goes by.

Designing inventory management database?

I am designing data base for inventory management system which is used by nearly 10 to 15 companies. This database contains nearly 25 tables.For designing database i'm planning to use shared schema architecture(ie each schema corresponding to a company and these all schemas are to be placed in a single database).
i want to know whether it is reliable to use shared schema architecture.
can any one please tell me is it correct decision to use above mentioned architecture.
Thanks in advance..
If I read your question, you are suggesting that each company has its own schema. This means two things:
If you decide to implement a basic change in the schema (ie not a change that one company requests), then you will have to implement this change in all the schemae.
You will probably have to implement different logic in your front
end program for each company.
Better you should develop one schema for the entire database; each table would have a field called 'CompanyID' which naturally would define to which company each row belongs. This field would be a foreign key to the Companies table.

Resources