Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Visual support

like image 323
Vincent Poirier Avatar asked Oct 12 '16 13:10

Vincent Poirier


People also ask

Can database schema be changed?

A schema change is an alteration made to a collection of logical structures (or schema objects) in a database. Schema changes are generally made using structured query language (SQL) and are typically implemented during maintenance windows.

How do I change the schema in PostgreSQL?

ALTER SCHEMA changes the definition of a schema. You must own the schema to use ALTER SCHEMA . To rename a schema you must also have the CREATE privilege for the database. To alter the owner, you must also be a direct or indirect member of the new owning role, and you must have the CREATE privilege for the database.

Which command is used to change schema?

You can use DDL to add, modify, or remove schema objects as the database is running. For a list of all valid DDL you can use, see Appendix A, Supported SQL DDL Statements. You can do the following types of schema changes: Modifying Tables — You can add, modify (alter), and remove (drop) table columns.

How do you change the schema in a snowflake?

To rename a schema, the role used to perform the operation must have the CREATE SCHEMA privilege on the database for the schema and OWNERSHIP privileges on the schema. To swap two schemas, the role used to perform the operation must have OWNERSHIP privileges on both schemas.


2 Answers

Follow this simple steps (never miss step 4 and 5) :

  1. Open Model Tab

  2. 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'

  3. Go to the targeted schema. In my case is schema abc_develop_v2, right-click then Paste 'users'

  4. Next, copy table users from schema abc_develop_v2. Right-click table users then Copy 'users'

  5. 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.

like image 126
Marwan Salim Avatar answered Oct 19 '22 02:10

Marwan Salim


Use the model tab. You can cut out a table from one schema tab and insert it into another.

like image 39
Mike Lischke Avatar answered Oct 19 '22 02:10

Mike Lischke