Summary Chapter 7: Modeling tips and tricks 7. Introduction 7.4. Copy, cut, duplicate and delete objects

7.4. Copy, cut, duplicate and delete objects

Objects can be copied (Ctrl+C), cut (Ctrl+X), duplicated (Ctrl+D) and deleted (Del) in the database model. In the case of copy and cut operations you can also do these actions between the loaded database models as well. One caution should be taken when you are trying to cut or delete a set of objects: in pgModeler the objects are strongly linked and in some cases delete or cut certain objects may cause the removal of another ones not necessarily selected by the user. This happens mainly to relationships which generate columns that can be referenced by many other objects. If the user removes the relationship all the objects that reference the generated columns will be excluded as well.

For copy and cut operations, pgModeler offers to the user the option to copy the selected object's dependencies. This is useful when you are doing these actions between models and the dependencies don't exist on the destination. For instance, let's say you want to copy the table table_a that is under the schema schema_a and intend to paste it into another model but the mentioned schema does not exist there. What the copy dependencies does is to insert the schema_a in the list of objects to be copied and in the moment of pasting them in the second database model both table_a and schema_a are created there. In case of pasting objects on the database model where there are conflicting names, the pasted objects will be automatically renamed and will receive the suffix _cp in order to distinguish their names.

The duplicate operation works almost like a copy and paste in a single step. The difference is that, unlike the copy operation, it creates completely detached objects and is performed only in the current model. An example of detached object is a table which holds columns and constraints added by a relationship. When duplicating such table all columns and constraints are duplicated as well in the resulting table. This not happens on copy operation because it only considers objects that aren't added to the table by relationships. See the image below to have an idea of the results produced by the duplication and copy operations. On the left, the object public.table_b_cp is a result of a duplication from public.table_b, note that the resulting table has more objects compared to the same table on the right side of the image which denotes the result of a copy and paste operation.

Finally, the a delete cascade (Shift+Del) operation drops an object and all its children or references. But be careful when using this action because if there is one or more protected objects in the set to be dropped the whole operation is aborted but the ones already deleted aren't restored and in some cases the change is irreversible.

Sep 11, 2018 at 15:22