Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping tables within a MySQL database

Here's my ponder: I've got some ER diagrams representing several thousand tables in a database. The entities represented in each of the multiple files have some associative relationship as decided by the designer. While relationships exist between entities in other files, they are not mapped. This seems common practice for diagramming databases of this size.

I was entertaining the idea of representing these groupings in a MySQL database. As SCHEMA is an alias to DATABASE in MySQL, I'm not able to find a mechanism for grouping tables within a database.

I'm wondering if anyone else has devised some creative grouping concept that they would like to share with me. Or, better yet, if MySQL supports some mechanism for grouping tables within a database, please let me know. ( I've apparently missed it in my research )

like image 829
mbenson Avatar asked Dec 16 '10 21:12

mbenson


People also ask

Can you group tables in MySQL?

Simple answer: you can't. MySQL only supports a single level of namespace.

How do I group data in MySQL?

The MySQL GROUP BY Statement The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more columns.

How can you connect a group of tables within a database?

You do this by creating a third table, called a junction table or a relationship table, that has a primary key and a foreign key for each of the other tables. A one-to-many relationship is then created between each foreign key in the junction table and the corresponding primary key of one of the other tables.

Does MySQL have grouping sets?

Starting with MySQL 8.0. 1, the server supports the SQL GROUPING function. The GROUPING function is used to distinguish between a NULL representing the set of all values in a super-aggregate row (produced by a ROLLUP operation) from a NULL in a regular row.


3 Answers

You can use the same prefix for the tables you want to use, for example you have employees groups you make the tables emp_main and emp_Children and emp_tasks then you can have another group like items that you sell that starts all with it_

like image 149
mariana soffer Avatar answered Oct 19 '22 06:10

mariana soffer


There is no concept of a hierarchy in MySQL. ie. No folders, containers or namespaces for your databases.

MySQL has 2 concepts: A database (Often referred to as a Schema), and tables. Various software (like PHPMyAdmin) will look at the similarities and will group databases together into folders based on the name itself. For example, if you use underscores "com_sumeet" phpmyadmin will actually group those together:

like image 6
ugh StackExchange Avatar answered Oct 19 '22 06:10

ugh StackExchange


Unlike how Schemas in Postresql can be used to group tables into different namespaces, MySQL does not have native support for structuring tables in any other way than with prefixes. If you are using an admin tool like MySQL Workbench you can however use EER layers to group tables visually: https://dev.mysql.com/doc/workbench/en/wb-using-layer-tool.html

like image 3
Andreas Bergström Avatar answered Oct 19 '22 06:10

Andreas Bergström