One To Many relationships for Innerjoins? - mysql

Does a database relationship need to be established before you can impliment a INNERJOIN In a PHP Query?
Furthermore, when I export my Database via PMA; My already created relationships to not get exported. So I'm having to re-create my relationships apun every import.
Is it possible to export with the relationships?

No. The relationship is preferred when being optimized, but a relationship is not required to use a JOIN.
When exporting your database, make sure you use the Custom - display all possible options method. You may missing an option that is not including those constraints. Another possible reason is if you're not using InnoDb as the table engine, otherwise those constraints are discarded with MyISAM. See this question for more info.

Related

Add an attribute to many tables automatically

I have a database diagram in Workbench and this diagram is synchronized with my database. This database has more than 500 tables, and I need to add a new column to most tables, it is not a viable option to add it one by one and then synchronize the changes with the database. Is there any workbench option that allows me to add the field in bulk to many tables ?.
The only way I can think of is to make a script that automatically adds that attribute to the tables and then perform the inverse synchronization, that is, update the diagram from the database.
What do you think? Any better solution?

What is the best way to make two instances in Solr which use identical schemas?

I got indexed a Mysql database using Solr and everything is perfect. Now i got another database which uses exactly the same schema as my first database but with different data in it.
What i want is to use Solr to index also the second database using the same solr schema that i created for my first database since are completely the same!
I read that Solr cores allows you to run multiple instances that use different configuration sets and indexes, but in my case i got the same exactly configuration, the only thing that changes is the database name.
My question is what is the best way two create two Solr instances that use the same configuration?
Cheers
You could use two cores and share a schema. Just read the Wiki. But in practice you might want to keep the flexibility and just copy the schema for a second core.
How about using only one solr instance but have a field in the schema that contains a value which indicates which db/source the record came from.

Mysql workbench not showing realtions after reverse engineering database

I'm using MySQL workbench 5.2.35 CE to reverse a Mysql Database and show the diagram of tables with their relationships.
I am able to get every table and its fields but the relations between them is not shown. Why is that? Is there any way it can be fixed?
Most often, the relations between tables are not stored in the DB. How to combine two tables is entirely up to the SQL query and because there are near endless possibilities to name your columns this is not easy to guess. Try to find some SELECT statements or use brute force to find out wich columns match.
If you are using MyISAM as the database engine, your database is not fully relational. Make your database fully relational by using InnoDB engine. Then you will be able to see the relations when you do reverse engineering. But please note that each has pros and cons of its own. Google MyISAM vs InnoDB to find out more about the differences.
I have tested mysql-workbench for both 5.2 and 6.0 latest version. My database got foreign key constraints defined clearly. My database is using mysql-native SQL. But the relationships are shown as line between tables. I have created another test database with only two tables. In this case the InoDb was used as engine. The foreign key constrain clearly defined. Still it only generate two lonely table object in the ER diagram after going through the "reverse engineering" module.
While using another commercial software, I was able to generate the 'lines' between the Entities.
My question is, is this a problem of workbench itself, or some error on my part. My database server is the latest stable version 5.6.12. If I can get an answer, this will be good for everyone. You don't have to waste time trying to get an ER-diagram with this piece of software.

Determining dependent tables in MySQL?

In MySQL, I need to know which tables depend on other tables. Is it possible to get the relations?
In SQL Server it's possible to see dependent tables. I hope MySQL can do this too.
If it's in pictorical form then that's even better.
Perhaps you want the SHOW CREATE TABLE command?
If there are foreign keys defined, the above command will show you what they are.
Take a look at the information_schema, especially to key_column_usage table.
http://dev.mysql.com/doc/refman/5.0/en/key-column-usage-table.html
Have a look at Database Explorer (object dependency tree) - a unique feature in dbForge Studio for MySQL.
Easily explore object's references and dependants in Database Explorer. Compilation of dependants for debugging is now also available through the object's context menu.
Also, Database Designer can show foreign key relations between tables.
maybe you'd want a graphical front-end to mysql since you're so used to SQL Server. if the foreign keys are defined, it will show up as a link between entities when you reverse engineer the database.

What is the MySQL equivalent of a PostgreSQL 'schema'?

I have a PostgreSQL database whose tables are divided amongst a number of schemas. Each schema has a different set of access controls; for example, one schema might be read-only to regular users, while they are allowed to create tables on another. Schemas also act as namespaces, so users don't have to worry about duplicating existing tables when they create new ones.
I want to create a similar setup using MySQL. Does it have an equivalent concept? If not, how can I most closely simulate it? I would prefer not to use multiple databases.
Database should be the closest one.
Prefixing table names is what's done with most MySQL-driven apps.