How do you change a table's schema? - mysql-workbench

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!

Related

How to know in Talend if tMySQLInput will overwrite data?

I have one already existing Talend Open Studio tMySQLInput component with some sql code inside it, in order to retrieve some joined columns linked to a tMySQLOuput component (pointing to an already existing MySQL table) with few records.
QUESTION:
Will the "tMySQLInput" component overwrite the already existing table data that the tMySQLOutput component relates to? I mean is there an option to check in the tMySQLInput our output in order to say, overwrite each time this job is executed ?
Thank you all.
Yes, there is an option where in tMySQLOutput where you can specify what action you want to do to your table. Follow following steps:
Go to component tab of tMySQLOutput, it will open the basic settings of this component.
If you will look closer you will find Action on table. This is the action which you can perform on the table which is pointed by tMySQLOutput. It has options as Default, Drop and Create Table etc.
Then you have Action on data. These are the options which you can perform on the data like Insert, Update etc.
In your case I suppose you can choose Action on Table as Default and Action on Data as Insert. Default action would not do anything on the table and Insert option would insert the records at the end of table. But in case of Insert if you will have duplicate rows then job would stop the moment it will find any duplicate row.

Access Select specific tables to update, change and modify

I create a DB where each table is a different project.
However, i am not sure how i would go about creating a form in which a user can choose a specific table (project) from a drop down menu and than be able to update/edit/modify the contents in the table.
Each table is standardized to contain exact column headers.
Thanks in advance for you help.

Is it possible to create table templates in Filemaker?

I'm using Filemaker Pro 12 and I was wondering if there is a way of creating a template for tables. There are a number of fields I'm placing in my tables that are identical utility-fields like modification time-stamp, active/inactive flags, etc. I was hoping there was a way that I could define the skeleton of each table somehow instead of having to manually add these identical fields every time.
If you are using the Advanced version, you can copy&paste fields among tables/files.
Using the regular version, you can import records from your "default" table and specify [New Table...] as the target table. This will recreate the source table's structure in the target file. The source table does not have to contain any records for this to work.
To expand a little bit on michael-hor257k's answer, if you're using FileMaker Pro Advanced, a good practice is to create a "Default" table that has your core utility fields. When you want to make a new table in Manage Database, instead:
Highlight the Default table,
Copy & Paste the table, then
Rename the new table.

How to avoid generating database table everytime

I am using MVC 3. I use Model first approach.
I created the Product Entity, in model folder. Which contains
ProductID
Name ---properties.
then, I create the SQL table from that model,It generates SQL table perfectly.
(I right click on model image and selects the option 'Generate database from model...'
then SQL window pop ups which contains all the DB scripts and I execute it.)
Now problem comes when, If I want to make changes in that model.
I have to recreate the table each time,so my data get lost.
whether, I have to generate SQL table every time when I make change in model?
How to avoid it?

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.