How do I delete a table from the MySQL Workbench catalog? - mysql-workbench

Recently I started using MySQL Workbench to design my data structures with an UML diagram. However, there is one thing I could figure out.
It seems that if I delete a table from the EER-diagram view, the table persists in the catalog view (as illustrated by the screenshot below). I could find a way to delete from the catalog view and it still list in the foreign key table reference selection screen.
This is very confusing. How can I effectively remove the table (not only from the view but from the whole project?
Notice, the two question tables one of which I deleted in the view and redesigned.

In case if the right-click and delete didn't work,
Simply drag and drop the table from the Catalog Tree to the Design area. Then you will see the table gets inserted there. From there, right-click on the table and select delete table. Then the table will get deleted from the whole project (assuming correspondent objects which are needed deleting as well).

Just had this problem before.
CMD + Backspace / delete on the keyboard will only delete the figure in the designer.
To completely delete the table and figure, instead try: Right-click > Delete 'table'.

I am using "MySQL Workbench Community (GPL) for Mac OS X version 6.2.3 revision 12313 build 2282 (32 bit)" and the action "delete 'table'" in the context menu (right-click on the table) did not work for me.
Believe it or not I had to restart the whole application. After the restart the delete action worked as expected. (1 object(s) deleted) [nothing about the object is kept in the DB]

This is how I discovered the difference between "delete" and "remove figure".
The "delete" deletes tables from the whole project, the "remove figure" only from the diagram (the tables still stay in the catalog).

Related

Only 3/4 tables were created under Navigator/Schemas in MySQL Workbench

I have created 4 tables total but can only see 3 of them under navigator/schemas in the area where you can write code. Why is that? The 3 tables I can see are all referencing the table that I can't see and all have foreign keys that reference the same column in the table I can't see under navigator/schemas.
refresh all under the database, that brings all to the left window, what you have done.
This you have to manually, because it is nit automatically refreshed, so a `Refresh all** exists at every node in the tree view

How do you change a table's schema?

We have a MySQL Workbench project with two tabs (two schemas/two databases).
If we create a table in the first tab, it's attached to the schema
magikweb_dev_igcweb.
If we create a table in the second tab, it's attached to the schema
magikweb_dev_igcweb_archive.
If we copy-paste/duplicate a table from the first tab to the second tab, the resulting table remains in the first schema. How can you change a table's schema?
Each schema is linked with a specific database, so when we use the "Synchronize Model..." feature, it links all the tables properly.
Use the model tab. You can cut out a table from one schema tab and insert it into another.
The cut-and-paste method described in another answer works well for tables with no foreign keys, and for a reasonable number of tables.
An alternative that preserves foreign keys is to export the model as a SQL script, edit it, and then import the new script into a new model.
Using MySQL Workbench v6.3:
File -> Export -> Forward Engineer SQL Script
Carefully edit SQL script. Replace references to one schema with the other, for the tables you want to move. Do this both for CREATE TABLE commands and foreign key references.
File -> New Model
File -> Import -> Reverse Engineer SQL Script
Unfortunately you will then need to recreate any diagrams. But that can be straightforward if you have the original diagram as reference (take a screenshot or export it to PNG or PDF.)
Follow this simple steps (never miss step 4 and 5) :
Open Model Tab
Choose source schema. In my case, I want to copy table users from schema abc_develop_v1 to schema abc_develop_v2 then paste to diagram . So I choose schema abc_develop_v1, right-click table users then Copy 'users'
Go to the targeted schema. In my case is schema abc_develop_v2, right-click then Paste 'users'
Next, copy table users from schema abc_develop_v2. Right-click table users then Copy 'users'
Go to your diagram and Paste 'users'.
That's all. Your table is ready in your diagram with the right schema :-)
Notes: You can double check by double-click on the table in your diagram, and look at the right corner. It will show the Schema name.
I found a less painful way to do this.
Save and backup your diagram and your schema.
Display schema's name before table's names in diagram. This will make the next step easier.
Right-click on the tables which are on the wrong schema, and select "Copy SQL to clipboard". Paste the script in a new SQL window. Repeat for each table you want to migrate.
Edit the script to change the schema name. Watch for any miss in entries, the wrong schema might be a reference at any line. Mine was mydb, which I don't remember creating. Execute the script. Now you have the tables on the right schema.
Synchronize your model. Be sure to check "Update the model" for each missing table, otherwise, the tables will be deleted from the schema :)
Drag'n'drop the newly created tables into the diagram. Then remove the ones which are using the wrong schema. Tip: tables that are not in diagram won't display a dot next to their name.
Optionally, you can delete the faulty schema from the model so this never happens again. Be sure to know what you're doing first!

Some fields are missing in the fieldexplorer. How to show all fields?

i'm using Crystal Reports with my ERP-System. There have been predefined reports i now want to change.
In the field-explorer are some tables which have been renamed for better readability. But those tables are missing some fields, i want to use. If i connect the whole table again, all fields are there. Is there a way to display all fields in the predefined tables.
I tried to refresh the Database but nothing changes. If i delete the predefined table and then rename the new one to the old one, so i can use all predefinded formulas, all used fields in the report get deleted. I would need to recreate the whole report then.
Thanks for the help
If it is truly the same table and is not showing all the fields then you need to do "Database > Verify Database". That will force CR to refresh the structure of the table (instead of just the data). If this doesn't add the missing fields then the table in the report is actually a different object.
To see what the table/view the report is actually using go to "Database > Set DataSource Location" and look at the properties node for that table. It will show if it is a table/view/SP and what the true object name is.
If you want to replace the existing table with a different table you go to "Database > Set DataSource Location" again. Highlight the existing table in the top window, connect and highlight the replacement table in the bottom window. Then click update. Crystal will replace one table with the other and all of the fields in the report that exist in the new table will be mapped automatically. Note that the new table will keep the alias of the original table. If you are unsure if the table was updated you can look at the properties node in the top window to see the change.

How do I point Crystal Reports at a new database

I have a Crystal Reports 2008 user that has over 100 custom developed reports.
The reports all query Sql Server databases (SQL 2005).
This database server is getting replaced with a new system (running SQL 2008 R2) and the existing databases will be moved to the new server.
The new database server will have a different name (which I can address via the Crystal Reports Connections),
however, one of the applications is also being upgraded at the same time. The old database (DB_A) will be restored on the new server for historical reporting and a new database (DB_B) will be created.
The new DB_B will have a very similar schema, so I would expect that most of the Crystal Reports should be able to run against the new DB_B with little or no modification other than pointing the report definition at the new DB_B.
Of course, the majority of my users custom developed reports query against DB_A.
My question is: How do I modify existing Crystal Reports files to point at the new database name (DB_B) instead of the old database (DB_A) ?
Use the Database menu and "Set Datasource Location" menu option to change the name or location of each table in a report.
This works for changing the location of a database, changing to a new database, and changing the location or name of an individual table being used in your report.
To change the datasource connection, go the Database menu and click Set Datasource Location.
Change the Datasource Connection:
From the Current Data Source list (the top box), click once on the datasource connection that you want to change.
In the Replace with list (the bottom box), click once on the new datasource connection.
Click Update.
Change Individual Tables:
From the Current Data Source list (the top box), expand the datasource connection that you want to change.
Find the table for which you want to update the location or name.
In the Replace with list (the bottom box), expand the new datasource connection.
Find the new table you want to update to point to.
Click Update.
Note that if the table name has changed, the old table name will still appear in the Field Explorer even though it is now using the new table. (You can confirm this be looking at the Table Name of the table's properties in Current Data Source in Set Datasource Location. Screenshot http://i.imgur.com/gzGYVTZ.png) It's possible to rename the old table name to the new name from the context menu in Database Expert -> Selected Tables.
Change Subreports:
Repeat each of the above steps for any subreports you might have embedded in your report.
Close the Set Datasource Location window.
Any Commands or SQL Expressions:
Go to the Database menu and click Database Expert.
If the report designer used "Add Command" to write custom SQL it will be shown in the Selected Tables box on the right.
Right click that command and choose "Edit Command".
Check if that SQL is specifying a specific database. If so you might need to change it.
Close the Database Expert window.
In the Field Explorer pane on the right, right click any SQL Expressions.
Check if the SQL Expressions are specifying a specific database. If so you might need to change it also.
Save and close your Formula Editor window when you're done editing.
And try running the report again.
The key is to change the datasource connection first, then any tables you need to update, then the other stuff. The connection won't automatically change the tables underneath. Those tables are like goslings that've imprinted on the first large goose-like animal they see. They'll continue to bypass all reason and logic and go to where they've always gone unless you specifically manually change them.
To make it more convenient, here's a tip: You can "Show SQL Query" in the Database menu, and you'll see table names qualified with the database (like "Sales"."dbo"."Customers") for any tables that go straight to a specific database. That might make the hunting easier if you have a lot of stuff going on. When I tackled this problem I had to change each and every table to point to the new table in the new database.
Choose Database | Set Datasource Location... Select the database node (yellow-ish cylinder) of the current connection, then select the database node of the desired connection (you may need to authenticate), then click Update.
You will need to do this for the 'Subreports' nodes as well.
FYI, you can also do individual tables by selecting each individually, then choosing Update.

Tables don't show when re-adding them to entity-model (edmx)

I have a db with 5 tables. At the beginning, I've added those tables in, but then decided to remove some due to some relationship compile error.
Now, when i want to add them back, i'm opening the edmx file -> update model from database... I don't see those tables under add tab, but only under the "refresh" tab.
How can i add them back?
In order to re-add a table to your model you will first need to delete the table from your model. (a list of tables is visible in the [model.Store] tree (see 'Model Browser' pane- you can open it from right-mouse click menu).
When you run 'Update model from database...' the table will appear in the 'Add' tab in the first step of the 'Update Wizard'.
Steps to complete:
Close your model in Visual
Studio.
Open your .edmx file in a
text editor.
Search and delete
the xml entity elements (see notes
below).
Open your model in Visual
Studio.
Click Update Model from
Database.
To delete all references to a table in your Model:
In the 'EntityContainer' element,
delete all 'EntitySet' child elements
that have the 'Name' attribute set to
the value [TableNameToReAdd].
In the
'EntityContainer' element, delete all
'AssociationSet' child elements where
an 'End' element exists that have
their 'EntitySet' attribute set to
the value [TableNameToReAdd].
In the
'EntityContainer' element, delete all
'EntityType' child elements where
that have the 'Name' attribute set to
the value [TableNameToReAdd].
In the
'EntityContainer' element, delete all
'Association' child elements where an
'End' element exists that have their
'Role' attribute set to the value
[TableNameToReAdd].
I reading this and other searching option, but finally I have found another answered which help me to short-out this issue.
From the error message looks like one of your table/view doesn't have
a primary key. EF needs every table to have a primary key in order to
generate Entity keys. You may still be able to run your application,
but I strongly suggest you add primary keys as warned.
Link which solved my issue.
Updated
If some time you done everything fine, still does not reflect the changes either adding a new column or change data-type.
The best way of this try to update manually, still there is no hope, then as suggested #mathijsuitmegen, delete and add the table, but this is last option to prefer.
An easier solution is in the Model Browser under
[modelName].Store -> Tables/ViewS
delete the table not showing up. Then right click on the model "update from database" and the table should be there.
You want to re-add an entity after it is deleted in the model.
Besides editing the edmx file there's another way to do this.
You will have to temporary delete the table from the database.
note: I would only to this if the database is not in production yet!
So in SQL Server Management Studio first create a script:
right click on the table(s) that correspond with the missing entity in your model. Select 'Script Table as', 'CREATE To', 'New Query Editor Window'.
The Second step is to delete the table. Right click again and select 'Delete'. Confirm the delete.
Back in Visual Studio do an update of the model.
Go back to SQL Server Management Studio and run the 'create' script you have just created.
The table will be added to your database again.
In Visual Studio you can now do an update again, your table will show up under the 'add ' tab!!!
In addition to the above list of references that need to be deleted from the model please consider removing AssociationSetMapping element as well in case if your table has associative relationship with other tables.