EER mysql workbench diagram - cakephp

I'm new to CakePHP & Mysql Workbench and i just did a reverse engineer to a a open source application built with cakephp(Croogo CMS). In order to better understand the relations between tables I'll like to draw them, but using the mysql workbench the tables are getting new columns as foreign keys. I assume this isn't the right way to do it.
My questions are:
1) How to use mysql workbench in order to draw/see the relations between tables?
2) Do you know where can I find a EER mysql workbench diagram which use the cakephp convention and can help me to figure out, how this thing has to work?

The problem is that this CMS doesn't set proper relations in the database. That's why they are not retrieved from the DB.
If you know what is the relations between the tables (hopefully the Croogo CMS follow the Cake naming conventions) you can set relations between the tables by the icon "Place Relationship Using Existing Columns" (it's the last icon in the relation's toolbar). You need to select a column from a child table and then select the id column of the master table and the relation will be created.
Bear in mind that at least for me Workbench is a little bit unstable and crashes unsuspectingly - so save regularly your changes :)

You may find these graphics my Andy Dawson useful: https://github.com/AD7six/croogo/tree/mi/config/schema/graphics/

Related

SQL - Export Database Diagram - SSMS 17

I am trying to export 3 database (DB) diagrams from one DB to another using SSMS 17. I have tried the solution suggested here:
How to export a SQL Server 2008 Database Diagram to another DB?
This solution is also recommended in several other websites I have found so far, to copy the content of the table "sysdiagrams" from the source DB to the destination DB (3 rows in my case).
After doing this I can confirm that both "sysdiagrams" tables have the same content and the diagrams are imported in the destination DB. Nevertheless in each imported diagram I see only the tables but not the relationships. What I find strange is that the relationships are shortly visible while the tables in the diagram are being loaded. After all tables are loaded they just dissappear.
Does anyone know what the issue could be? It is my understanding, that this solution is successful for early versions of SSMS.
Any help is highly appreciated :) !
Check that the relations (Foreign Key constraints) actually exist in the target database, because if they don't then the diagram editor will behave exactly as you describe: initially it will draw all lines, then it starts looking for each FK relation that each line represents, and it will one by one remove lines for which relations are not found.
To clarify, you can create FK relations using the Diagram Editor by drawing a line between to tables (the editor then creates both a line in the diagram and the actual FK constraint). But with a 'copy diagram' action like yours, you copy only the line data but not the actual relations.
To add the missing relations in the target database you could write ALTER TABLE ... ADD CONSTRAINT ... statements, or use the Diagram Editor again on the target database, or you can try using a database diff tool.

How to discover associations between tables in a PostgreSQL database?

I'm dealing with a huge ERP database, hundreds of tables, and am having trouble figuring out how one entity is referenced from another. Let's call them the "sale" table and the "shipment" table. Each has FK relationships with numerous other tables, but no FK links either one to the other, and no obvious associative table is linked to both.
Is there any good way using SQL or the psql command line to discover the chains of relationships that connect the two tables?
Is there any good way to discover the chains that connect a specific row or PK of "sale" and a specific row/PK of "shipment"?
You should look at a tool like schemacrawler. It's good a opensource tool for data modelling retro-engineering.
You can find documentation here.

How to get database dependency/relationship among tables

Can anyone give me an idea about database flow diagram in my SqlServer Server Management Studio? I have a database (ERBIA) in my server; I want to know about the database relationship among different tables.
You can simply click on this:
And then select the tables for which you wish to create diagrams (graphs)
By database flow diagram I think you mean an Entity Relationship Diagram (ERD). There are a number of 3rd party tools that exist to create ERDs. ERWin, Visio, ER/Studio are some examples.
These tools can read the database schema information and create a diagram and draw relationship lines based on the Foreign Key constraints. You can edit the diagrams and depending on the tool update the database or generate a DDL script for the database changes.
SQL Server also includes a database designer, but it should be noted there is no separation from a logical model and the physical model. This means if you draw a line from one table to another indicating a relationship a FK will actually be created when you save the diagram. For some scenarios this would be a problem.

SqlServer: How to get meta-data about tables and their relationships?

I was wondering if there was a way (relatively simple I hope) to get information about the table and its attributes and realtionships?
Clarification: I want to grab all tables in the database and get the meta-model for the whole database, tables, column data, indicies, unique constraints, relationships between tables etc.
The system has a data dictionary in sys.tables, sys.columns, sys.indexes and various other tables. You can query these tables to get metadata about the database structure. This posting has a script I wrote a few years ago to reverse engineer a database schema. If you take a look at it you can see some examples of how to use the system data dictionary tables.
there are a whole bunch of system views in the information_schema schema in sql server 2005+. is there anything in particular you're wanting?
some of those views include:
check_contraints,
columns,
tables,
views
Try sp_help <tablename>. This will show you foreign key refrences and data about the columns, etc - that is, if you are interested in a specific table, as your question seemed to indicate.
If using .NET code is an option SMO is the best way to do it.
It abstracts away all these system views and tables hiding them behind nice and easy to use classes and collections.
http://msdn.microsoft.com/en-us/library/ms162169.aspx
This is the same infrastructure SQL Server Management Studio uses itself. It even supports scripting.
Abstraction comes at a cost though so you need maximum performance you'd still have to use system views and custom SQL.
You can try to use this library db-meta

How to put Database Tables in MVC Models

I'm new in developing in MVC and I have some doubts in how to build the Models. I don't know if I must build them in terms of Database Tables or in other terms.
I have for example this 5 tables:
Domain
Category_Domains
Countries_Domains
Categories
Countries
How can i Build a Models to do actions in these Database Tables. Should I built the SQL commands to Insert, Delete and Update for each one of these Tables or I should do other thing than this?
Sorry if I not explain well.
The best advice I can give you is to look into the entity framework. Using this framework, you can create a data connection to your SQL database and the framework will create your model based on your table structure, including relationships.
Doing this will ensure your database is modelled correctly and kept in sync at all times

Resources