Can we make nested database in MySQL? If yes how? - mysql

I don't know if it has another term for it but I want to basically create a directorial database having different databases in one major database and each containing their respective tables. Is there any way to do that in MySQL?
Something like this:

No, it is not possible to make a nested database in MySQL.
MySQL supports a simple and flat structure. You cannot nest databases (and of course not tables, nor fields).
If you want to group databases together in MySQL for any reason (like availability), then you can use a common prefix when naming them. For example, if you want to develop an HRM (Human Resource Management System), and it has let's say 3 parts namely: Inventory, Attendance and Leaves, then you can have the following database:
HRM_INVENTORY (created by CREATE DATABASE HRM_INVENTORY;)
HRM_ATTENDANCE (created by CREATE DATABASE HRM_ATTENDANCE;)
HRM_LEAVES (created by CREATE DATABASE HRM_LEAVES;)
Now regarding the image that you have shared in your question, PHPMyAdmin only tries to find common prefixes and group them together to make them easy to find for the user. For example if you create the 3 databases I just mentioned, PHPMyAdmin will group them together under HRM and if you collapse it, you can see all the three.

Related

SQL Database architecture with multiple end Users

I am making a web application where users get and manage data from multiple tables as well as create other users to access said data. currently I have it set up for one group of users.
My question is would it be better to have multiple databases in which each database has its own user which is stored in a master table("I don't like the sound of this one") or have a column in each table defining the user group that has access to it? Are either of these a good idea or is something else more appropriate?
You should have a column in each table. In my opinion, its the correct thing to do, and also you have only one database to do mantainance.
Just imagine the time it would take to add a column to a table in the future, and you should do it in multiple databases.

Organizing a database using folders in phpMyAdmin

Right now I have a database in phpMyAdmin, and off the the side of the screen, it shows the database name, and a list of tables inside the database. It's fine if it's only a couple of tables, but when there's dozens of tables, it gets hard to find the tables I want to edit. I've thought about creating another database to make it easier to organize, but then I'll have to connect using the different database's name and a different user login for the database, and I just thought how much easier would it be if I can make folders or something similar inside the database I already have to organize my tables. I'm wondering if something like this is possible, or anyone know any work-around this issue.
Well, you can't create a database (or folders) within a database; that's just not something MySQL is able to do.
phpMyAdmin has a grouping feature that may help your situation. By default, databases with a prefix followed by _ (a single underscore) will be grouped together, as will tables with __ (two underscores).
Here's an example of how this ends up looking when grouped:
Database:
Table:
If you're able to rename some of your tables, you'll be able to take advantage of the grouping feature to make the phpMyAdmin display a bit more manageable. Of course, this won't change the way other tools display the table list.
The configuration directives $cfg['NavigationTreeDbSeparator'] and $cfg['NavigationTreeTableSeparator'] control the separator used. The relevant documentation starts at http://docs.phpmyadmin.net/en/latest/config.html#cfg_NavigationTreeEnableGrouping and includes the next few line items.

How do I to add multiple directories to an SQL database while sharing the same schema?

A buddy of mine needed help adding multiple directories to an SQL database while sharing the same schema yet have different listings. I've scoured my "MySQL" books and Google, I can't find any definitive information. I was just hoping someone here knew how to do this.
To clarify, there are a total of 12 directories. 11 are to be searched independently of one another and the 12th (which already exists) will be a directory comprised of all 11 directories, all of which will have the same schema.
The goals are to create these unique directories using the existing schema model, and to upload multiple directory entries at a time to the directories.
Does this mean the names of the directory entries have to be unique (ie. Name_1, Name_2, Name_3, etc...?) Or, will it be a matter of duplicating the schema under a different name? Any advise will help.
A directory, in this context, is like a roledex. I mean to have 12 roledexes with each rolodex having unique entries frem eachother. How do you approach this database-wise?
After logging into your PHPMyadmin select or go in to the table you want to duplicate-and-rename, then click on "Operations." There you see a series of boxes with one called "Copy table to (database.table)" You can choose to duplicate structure and data, or structure only. Type the name you want and click go. And your new table with listing will be ready to edit and search!
If I understand what you're asking... I think you want to create a new database for each "directory," as you put it, with the same table definitions in it.
The word "database" in mySQL parlance means the same thing as "schema" in the parlance of some other RDBMS systems. You can't have two sets of data with the same table names in the same database (a/k/a schema). You need a different schema for this.
It's very common to have lots of databases in a single server with precisely the same tables / columns / keys etc. And yes, phpmyadmin can handle this.
The word "directory" is confusing, though. It ordinarily refers to the on-disk data storage used by the mySQL (RDBMS) server program. But I don't think that's what you mean. If you DO mean it, please make sure you are highly skilled at system administration before you try to muck around with the file systems on the mySQL server. It's easy to break stuff. (Ask me how I know how easy it is to break stuff :-) :-)

How to Map/Merge multiple tables?

I am new to SQL, I am trying to "map" data from several tables in ONE database to create ONE table with relational information. For example, I am trying to take data from my tables ps3_productcategories, ps3_categories and "map"/"merge" to the ps3_products table, The previous tables contains all the "category information" needed to map to "correct products".
I am trying to "MAP" the productID to the "correct"=> categoryID=> categoryName=> categoryParent etc.....
Any help would be appreciated
I suggest you look into views, it may be what you are looking for, although they do not create this in another database they do allow to create virtual tables from existing data.
A database View is known as a "virtual table" which allows you to query the data in it.
See the MySql manpage on views..
And here is a small tutorial on the subject.
If you really need this in a seperate database, you can easily create a view and export the results of that, and import it in other database.

Create ERD for a mySQL DB by selecting only some of the main tables

I need to create an ERD for our DB system. As it happens, there are lots and lots of tables, and no one really understands much of it. What's more, the same DB has tables for different applications, so not all tables are relevant to my application. I need an ERD for only my application's tables.
I tried creating ERD from MySQL workbench. It allows me to select a subset of the tables to put on an ERD, but that's the problem: I don't know which tables to select ( One of the reasons to build the diagram in the first place :-) ).
What I do know are some of the 'main' tables involved. What I'm looking for is this: I tell the tool some 5-10 of these main tables I'm interested in, and the tool automatically picks up all the tables that are linked to these tables, and creates the ERD for them.
Any pointers?
Otherwise, I'll have to live with building my list of tables manaully, one by one...
http://www.fabforce.net/ has a nice tool called DBDesigner, I have used this in the past for some reverse engineering on a datamodel.