What's the best way to design an Entity / Relationship Model? - mysql

For example if I have 20 tables, I have to design it by section? i.e
CLIENT (id, name...) -- orders -- ODERS_DETAIL(id, products...)
.
.
.
lives --- ADDRESS(...)
Or I can use The MySQL Workbench EER Model (To me, it looks like the Pysical Model)?
Or like this: Data Modeling Levels

Well, I would not do it in code. That is for the RDBMS itself.
MySQL EER Workbench does not do true entity modeling - it is modeling tables, you are correct.
If you want true ER modeling I suggest Oracle's newly released ('Early Adopter') SQL Developer Data Modeler.
It is pretty easy to use, is free and can forward and reverse engineer models to tables. http://www.oracle.com/technetwork/developer-tools/datamodeler/overview/index.html

When in doubt, design a table that is totally flat, and then determine where you have duplicated data, these can be considered for tables (entities).
The "ER model" defines entities unto themselves and allow the reference of entity-to-entity (table-to-table) through a separate relation. If you can remove yourself from thinking about foreign keys in your entities and focus on the relations in their own separate table.

Related

How to create this structure in mysql databases

I need to create such a structure, there is a category of products, each category stores its own information, for example, be entered phone information when selecting a phone category, computer information must be entered when selecting a computer category, How to create this structure in a clean database? , how is it done in a real project?
Before creating a 'structure' in a DB you need to design your Entity-Relationship Diagram.
This means that you need to decide the Entities of your problem, these would be your tables later in the DB, the Relationships between the entities, these have multiple ways that can be depicted in the tables based mainly on their cardinality and then the properties of the entities, which will be the fields of the tables in your DB.
I think that you need to start from that, create the ER Diagram and then try to model it into the DB.

MySQL Design: Seperate Schema or Table Prefixes?

I have a hobby project where I am creating my own software that will have different modules. The idea is to make the modules stackable and can be toggled off and on. I am using MySQL as the database back-end, and am wondering if it is better to have module-specific tables on their own schema, or if te tables should be prefixed. For example, let's say I have a systems module and an employees module; would putting all tables related to employees on an employee scheme be better than just prefixing the table names with something like "emp_"?
Prefixing table names is usually unnecessary clutter; the table names or the tables you are JOINing to should make it obvious what is going on. There is no performance difference between all-tables-in-one-db vs several dbs; there is a slight syntax diff.
This is kind of a moot point for MySQL, because databases and schema are interchangeable in MySQL. It would be more relevant for SQL Server.
My MySQL the keyword database was renamed into schema because they are not separated database. You can still have relationships across schemas.
In some ORM such as Laravel Eloquent you can write relationships such as:
$company->hasMany(Employee)
In this kind of relationship you will have a pivot table named company_employee. If you have two separated schemas, where do you want to put your pivot table? On the company schema or on the employee schema?
Laravel will fail to solve this question and it not trivial to create such relationship across schemas.

Many-to-many dimensions in a datawarehouse using Mondrian schema

I'm using mondrian-olap JRuby gem to query a datawarehouse using Mondrian library. I'm trying to build the OLAP schema but i'm having trouble setting a dimension composed by a many-to-many relationship.
I have a product with many categories, and so I created a table Product, a table ProductCategory and a table Category. The number of products is always increasing and so, using a single ProductCategory table seems a bit risky to me.
The Mondrian documentation was inconclusive for me, and all existing schema examples with a snowflake schema use only a single relationship table (like ProductCategory) and not a many-to-many combination of ones.
Is it possible to represent a many-to-many relationship using a Mondrian schema? Is there a better way to set this relationship?
Mondrian does not support many-to-many relationships. This is a feature that we have already started looking into, but there are no ETA as of now.

One to many relationship in ER diagram, MySQL Workbench

Hi I'm drawing an ER Diagram using MySQL Workbench for my final year project. It's about a shipping company, where buyer & shipping agent are involved in a shipping process with my client.
So far the buyer and agent have same attributes. So I decided to keep both of their data in a table and differentiate them using an attribute (type in my case).
As you see in my picture I couldn't able to make a N:M relationship between shipping table and external table. It always give me 1:M relationship. When I try to do the relationships manually it creates a another relational table and make a 1:M relation with it.
Can anyone assist me with my problem? Further how efficient to have a relational table in my case.

Relational DB Concept

I am trying to lay out the concept for a Relational DB and I ran into some conceptual Problems:
If I have multiple discrete Entities that are "nested" in each other/have a hierarchy e.g.:
Bosses can have multiple Employees. These employees have different Projects they do and One Project has again multiple sections.
So
B1-Bn:
E1-En
P1-Pn
Section1 -SectionN
How would that be best mapped in a database?
Or in other words, how is this hierarchy best mapped in a relational db?
Now I have Costumers that interact with these Employees.
They are met by the bosses
Then they decide which employee will work for them.
Then they are assigned Projects, with one or more sections.
How would that be best mapped.
the Relations 1-n, m-n, 1-1: Can they be used for e.g.:
This is a Foreignkey because of the 1-n relationship.
This is a ManytoManyField because of the m-n relationship.
And is there a excellent online tool to better understand/visualize that.
Thanks so much for your time!
You may want to follow a course on relational database design; this subject takes more than a few days to explain or master. But you are on the right track.
The first thing you may be seeing is a hierarchy, but before you know it there will be relationships that aren't hierarchical, so a network is formed.
This is why relational databases do not work with hierarchies.
You identify different types of entities and have one table for each type.
For each entity type you identify the properties of such entities - each property will be a column of the table.
If a property does not have an atomic value, but a structured value, these structured values must be regarded as an entity, and must be given its own table, and the property will be a foreign key referring that table.
In this way, you will form a network of tables linked by foreign keys. This is called an entity-relationship diagram. Many designers advocate creating such a diagram first, without mapping the entity types to tables directly. They allow many-to-many relationships between entity types in the diagram. A foreign key between tables on the other hand is always many-to-1 or 1-to-1. So these designers have an "implementation" step in which they introduce an additional table for each many-to-many relationship. Personally I don't use many-to-many relationships in my diagrams to begin with.